mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-08-04 15:18:17 +00:00
refactor(core): move assert_*!() macros
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
fb8f12a62e
commit
40cd8405f2
12 changed files with 50 additions and 38 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -2113,6 +2113,7 @@ name = "ironrdp-connector"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"ironrdp-core",
|
||||
"ironrdp-error",
|
||||
"ironrdp-pdu",
|
||||
"ironrdp-svc",
|
||||
|
@ -2147,6 +2148,7 @@ dependencies = [
|
|||
name = "ironrdp-dvc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ironrdp-core",
|
||||
"ironrdp-pdu",
|
||||
"ironrdp-svc",
|
||||
"slab",
|
||||
|
@ -2217,6 +2219,7 @@ dependencies = [
|
|||
"byteorder",
|
||||
"der-parser",
|
||||
"expect-test",
|
||||
"ironrdp-core",
|
||||
"ironrdp-error",
|
||||
"lazy_static",
|
||||
"md-5",
|
||||
|
@ -2330,6 +2333,7 @@ name = "ironrdp-svc"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"ironrdp-core",
|
||||
"ironrdp-pdu",
|
||||
]
|
||||
|
||||
|
|
|
@ -21,9 +21,12 @@ arbitrary = ["dep:arbitrary"]
|
|||
[dependencies]
|
||||
arbitrary = { version = "1", features = ["derive"], optional = true }
|
||||
ironrdp-svc.workspace = true
|
||||
ironrdp-core.workspace = true
|
||||
ironrdp-error.workspace = true
|
||||
ironrdp-pdu = { workspace = true, features = ["std"] }
|
||||
rand_core = { version = "0.6", features = ["std"] } # TODO: dependency injection?
|
||||
rand_core = { version = "0.6", features = [
|
||||
"std",
|
||||
] } # TODO: dependency injection?
|
||||
sspi.workspace = true
|
||||
tracing.workspace = true
|
||||
url = "2.5"
|
||||
|
@ -39,4 +42,3 @@ winapi = { version = "0.3", features = ["std"] }
|
|||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ pub struct Config {
|
|||
pub performance_flags: PerformanceFlags,
|
||||
}
|
||||
|
||||
ironrdp_pdu::assert_impl!(Config: Send, Sync);
|
||||
ironrdp_core::assert_impl!(Config: Send, Sync);
|
||||
|
||||
pub trait State: Send + fmt::Debug + 'static {
|
||||
fn name(&self) -> &'static str;
|
||||
|
@ -176,7 +176,7 @@ pub trait State: Send + fmt::Debug + 'static {
|
|||
fn as_any(&self) -> &dyn Any;
|
||||
}
|
||||
|
||||
ironrdp_pdu::assert_obj_safe!(State);
|
||||
ironrdp_core::assert_obj_safe!(State);
|
||||
|
||||
pub fn state_downcast<T: State>(state: &dyn State) -> Option<&T> {
|
||||
state.as_any().downcast_ref()
|
||||
|
@ -241,7 +241,7 @@ pub trait Sequence: Send {
|
|||
}
|
||||
}
|
||||
|
||||
ironrdp_pdu::assert_obj_safe!(Sequence);
|
||||
ironrdp_core::assert_obj_safe!(Sequence);
|
||||
|
||||
pub type ConnectorResult<T> = Result<T, ConnectorError>;
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
// Trait that can only be implemented within the current module
|
||||
pub(crate) mod private {
|
||||
#[doc(hidden)]
|
||||
|
|
24
crates/ironrdp-core/src/macros.rs
Normal file
24
crates/ironrdp-core/src/macros.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
/// Asserts that the traits support dynamic dispatch.
|
||||
///
|
||||
/// From <https://docs.rs/static_assertions/1.1.0/src/static_assertions/assert_obj_safe.rs.html#72-76>
|
||||
#[macro_export]
|
||||
macro_rules! assert_obj_safe {
|
||||
($($xs:path),+ $(,)?) => {
|
||||
$(const _: Option<&dyn $xs> = None;)+
|
||||
};
|
||||
}
|
||||
|
||||
/// Asserts that the type implements _all_ of the given traits.
|
||||
///
|
||||
/// From <https://docs.rs/static_assertions/1.1.0/src/static_assertions/assert_impl.rs.html#113-121>
|
||||
#[macro_export]
|
||||
macro_rules! assert_impl {
|
||||
($type:ty: $($trait:path),+ $(,)?) => {
|
||||
const _: fn() = || {
|
||||
// Only callable when `$type` implements all traits in `$($trait)+`.
|
||||
fn assert_impl_all<T: ?Sized $(+ $trait)+>() {}
|
||||
assert_impl_all::<$type>();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ default = []
|
|||
std = []
|
||||
|
||||
[dependencies]
|
||||
ironrdp-core.workspace = true
|
||||
ironrdp-svc.workspace = true
|
||||
ironrdp-pdu = { workspace = true, features = ["alloc"] }
|
||||
tracing.workspace = true
|
||||
|
@ -27,4 +28,3 @@ slab = "0.4"
|
|||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ use alloc::vec::Vec;
|
|||
// Re-export ironrdp_pdu crate for convenience
|
||||
#[rustfmt::skip] // do not re-order this pub use
|
||||
pub use ironrdp_pdu;
|
||||
use ironrdp_pdu::{assert_obj_safe, cast_length, encode_vec, other_err, PduEncode, PduResult};
|
||||
use ironrdp_core::assert_obj_safe;
|
||||
use ironrdp_pdu::{cast_length, encode_vec, other_err, PduEncode, PduResult};
|
||||
use ironrdp_svc::{self, AsAny, SvcMessage};
|
||||
|
||||
mod complete_data;
|
||||
|
|
|
@ -18,23 +18,24 @@ doctest = false
|
|||
[features]
|
||||
default = []
|
||||
std = ["alloc", "ironrdp-error/std"]
|
||||
alloc = ["ironrdp-error/alloc"]
|
||||
alloc = ["ironrdp-core/alloc", "ironrdp-error/alloc"]
|
||||
|
||||
[dependencies]
|
||||
bitflags.workspace = true
|
||||
ironrdp-core.workspace = true
|
||||
ironrdp-error.workspace = true
|
||||
tap = "1"
|
||||
|
||||
# TODO: get rid of these dependencies (related code should probably go into another crate)
|
||||
bit_field = "0.10"
|
||||
byteorder.workspace = true # TODO: remove
|
||||
byteorder.workspace = true # TODO: remove
|
||||
der-parser = "9.0"
|
||||
thiserror.workspace = true
|
||||
md5 = { package = "md-5", version = "0.10" }
|
||||
num-bigint = "0.4"
|
||||
num-derive.workspace = true # TODO: remove
|
||||
num-derive.workspace = true # TODO: remove
|
||||
num-integer = "0.1"
|
||||
num-traits.workspace = true # TODO: remove
|
||||
num-traits.workspace = true # TODO: remove
|
||||
sha1 = "0.10"
|
||||
x509-cert = { version = "0.2", default-features = false, features = ["std"] }
|
||||
pkcs1 = "0.7"
|
||||
|
@ -45,4 +46,3 @@ lazy_static.workspace = true # TODO: remove in favor of https://doc.rust-lang.or
|
|||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ pub trait PduEncode {
|
|||
fn size(&self) -> usize;
|
||||
}
|
||||
|
||||
assert_obj_safe!(PduEncode);
|
||||
ironrdp_core::assert_obj_safe!(PduEncode);
|
||||
|
||||
/// Encodes the given PDU in-place into the provided buffer and returns the number of bytes written.
|
||||
pub fn encode<T>(pdu: &T, dst: &mut [u8]) -> PduResult<usize>
|
||||
|
|
|
@ -205,30 +205,6 @@ macro_rules! cast_int {
|
|||
}};
|
||||
}
|
||||
|
||||
/// Asserts that the traits support dynamic dispatch.
|
||||
///
|
||||
/// From <https://docs.rs/static_assertions/1.1.0/src/static_assertions/assert_obj_safe.rs.html#72-76>
|
||||
#[macro_export]
|
||||
macro_rules! assert_obj_safe {
|
||||
($($xs:path),+ $(,)?) => {
|
||||
$(const _: Option<&dyn $xs> = None;)+
|
||||
};
|
||||
}
|
||||
|
||||
/// Asserts that the type implements _all_ of the given traits.
|
||||
///
|
||||
/// From <https://docs.rs/static_assertions/1.1.0/src/static_assertions/assert_impl.rs.html#113-121>
|
||||
#[macro_export]
|
||||
macro_rules! assert_impl {
|
||||
($type:ty: $($trait:path),+ $(,)?) => {
|
||||
const _: fn() = || {
|
||||
// Only callable when `$type` implements all traits in `$($trait)+`.
|
||||
fn assert_impl_all<T: ?Sized $(+ $trait)+>() {}
|
||||
assert_impl_all::<$type>();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/// Asserts that constant expressions evaluate to `true`.
|
||||
///
|
||||
/// From <https://docs.rs/static_assertions/1.1.0/src/static_assertions/const_assert.rs.html#51-57>
|
||||
|
|
|
@ -22,6 +22,7 @@ std = []
|
|||
[dependencies]
|
||||
ironrdp-pdu = { workspace = true, features = ["alloc"] }
|
||||
bitflags.workspace = true
|
||||
ironrdp-core.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -15,9 +15,10 @@ use std::borrow::Cow;
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use ironrdp_core::assert_obj_safe;
|
||||
use ironrdp_pdu::gcc::{ChannelName, ChannelOptions};
|
||||
use ironrdp_pdu::write_buf::WriteBuf;
|
||||
use ironrdp_pdu::{assert_obj_safe, mcs, PduResult};
|
||||
use ironrdp_pdu::{mcs, PduResult};
|
||||
use pdu::cursor::{ReadCursor, WriteCursor};
|
||||
use pdu::gcc::ChannelDef;
|
||||
use pdu::rdp::vc::ChannelControlFlags;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue