Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zlink-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ default = ["std", "server", "proxy", "tracing"]
std = ["dep:rustix", "dep:libc", "zlink-macros/std"]
server = []
proxy = ["zlink-macros/proxy"]
service = ["server", "zlink-macros/service", "introspection"]
service = ["server", "zlink-macros/service"]
# IDL and introspection support
idl = []
idl-parse = ["idl", "dep:winnow", "zlink-macros/idl-parse"]
introspection = ["std", "idl", "zlink-macros/introspection"]
introspection = ["idl", "zlink-macros/introspection"]

[dependencies]
serde = { version = "1.0.218", default-features = false, features = ["derive", "alloc"] }
Expand Down
11 changes: 10 additions & 1 deletion zlink-core/src/introspect/type/collections.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//! Type implementations for collection types.

use alloc::{
collections::{BTreeMap, BTreeSet},
string::String,
vec::Vec,
};

use super::Type;
use crate::{idl, idl::TypeRef};
use alloc::collections::{BTreeMap, BTreeSet};
#[cfg(feature = "std")]
use std::collections::{HashMap, HashSet};

// ============================================================================
Expand All @@ -23,10 +29,12 @@ impl<T: Type> Type for &[T] {
// Map types - Varlink maps always have string keys
// ============================================================================

#[cfg(feature = "std")]
impl<V: Type> Type for HashMap<String, V> {
const TYPE: &'static idl::Type<'static> = &idl::Type::Map(TypeRef::new(V::TYPE));
}

#[cfg(feature = "std")]
impl<V: Type> Type for HashMap<&str, V> {
const TYPE: &'static idl::Type<'static> = &idl::Type::Map(TypeRef::new(V::TYPE));
}
Expand All @@ -43,6 +51,7 @@ impl<V: Type> Type for BTreeMap<&str, V> {
// Set types - represented as arrays in Varlink
// ============================================================================

#[cfg(feature = "std")]
impl<T: Type> Type for HashSet<T> {
const TYPE: &'static idl::Type<'static> = &idl::Type::Array(TypeRef::new(T::TYPE));
}
Expand Down
2 changes: 2 additions & 0 deletions zlink-core/src/introspect/type/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Type implementations for primitive types.

use alloc::string::String;

use super::Type;
use crate::idl;

Expand Down
6 changes: 6 additions & 0 deletions zlink-core/src/introspect/type/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ impl Type for core::time::Duration {
const TYPE: &'static idl::Type<'static> = &idl::Type::Float;
}

#[cfg(feature = "std")]
impl Type for std::time::Instant {
const TYPE: &'static idl::Type<'static> = &idl::Type::Float;
}

#[cfg(feature = "std")]
impl Type for std::time::SystemTime {
const TYPE: &'static idl::Type<'static> = &idl::Type::Float;
}
Expand All @@ -45,10 +47,12 @@ impl Type for std::time::SystemTime {
// Path types
// ============================================================================

#[cfg(feature = "std")]
impl Type for std::path::PathBuf {
const TYPE: &'static idl::Type<'static> = &idl::Type::String;
}

#[cfg(feature = "std")]
impl Type for std::path::Path {
const TYPE: &'static idl::Type<'static> = &idl::Type::String;
}
Expand All @@ -57,10 +61,12 @@ impl Type for std::path::Path {
// OS string types
// ============================================================================

#[cfg(feature = "std")]
impl Type for std::ffi::OsString {
const TYPE: &'static idl::Type<'static> = &idl::Type::String;
}

#[cfg(feature = "std")]
impl Type for std::ffi::OsStr {
const TYPE: &'static idl::Type<'static> = &idl::Type::String;
}
Expand Down
13 changes: 10 additions & 3 deletions zlink-core/src/introspect/type/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
//! This module contains implementations for types that transparently wrap other types,
//! such as smart pointers, cells, and optional types.

use alloc::{
borrow::{Cow, ToOwned},
boxed::Box,
rc::Rc,
sync::Arc,
};

use super::Type;
use crate::{idl, idl::TypeRef};

Expand All @@ -22,11 +29,11 @@ impl<T: Type + ?Sized> Type for Box<T> {
const TYPE: &'static idl::Type<'static> = T::TYPE;
}

impl<T: Type + ?Sized> Type for std::rc::Rc<T> {
impl<T: Type + ?Sized> Type for Rc<T> {
const TYPE: &'static idl::Type<'static> = T::TYPE;
}

impl<T: Type + ?Sized> Type for std::sync::Arc<T> {
impl<T: Type + ?Sized> Type for Arc<T> {
const TYPE: &'static idl::Type<'static> = T::TYPE;
}

Expand All @@ -46,6 +53,6 @@ impl<T: Type + ?Sized> Type for core::cell::RefCell<T> {
// Cow type - transparent wrapper
// ============================================================================

impl<T: Type + ToOwned + ?Sized> Type for std::borrow::Cow<'_, T> {
impl<T: Type + ToOwned + ?Sized> Type for Cow<'_, T> {
const TYPE: &'static idl::Type<'static> = T::TYPE;
}
8 changes: 8 additions & 0 deletions zlink-macros/src/service/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ impl MethodInfo {
"at most one `#[zlink(fds)]` parameter is allowed per method",
));
}
#[cfg(not(feature = "std"))]
if !fds_params.is_empty() || return_fds {
return Err(Error::new_spanned(
&method.sig,
"FD-related attributes (`#[zlink(fds)]` and `#[zlink(return_fds)]`) \
require the `std` feature to be enabled",
));
}

// Extract return type and check if it's a Result or Stream.
let (
Expand Down
2 changes: 1 addition & 1 deletion zlink-smol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors.workspace = true
default = ["service", "proxy", "tracing"]
server = ["zlink-core/server"]
proxy = ["zlink-core/proxy"]
service = ["server", "introspection", "zlink-core/service"]
service = ["server", "zlink-core/service"]
idl = ["zlink-core/idl"]
idl-parse = ["zlink-core/idl-parse"]
introspection = ["zlink-core/introspection"]
Expand Down
2 changes: 1 addition & 1 deletion zlink-tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors.workspace = true
default = ["service", "proxy", "tracing"]
server = ["zlink-core/server"]
proxy = ["zlink-core/proxy"]
service = ["server", "introspection", "zlink-core/service"]
service = ["server", "zlink-core/service"]
idl = ["zlink-core/idl"]
idl-parse = ["zlink-core/idl-parse"]
introspection = ["zlink-core/introspection"]
Expand Down