1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
//! A specialized component system aimed at helping build a styling foundation
//! for Rust apps.
//!
//! This crate makes it easy to annotate types as [`StyleComponent`]s that can
//! be used within a [`Style`]. This crate provides no [`StyleComponent`]
//! implementors.
#![forbid(unsafe_code)]
#![warn(
clippy::cargo,
missing_docs,
clippy::pedantic,
future_incompatible,
rust_2018_idioms
)]
#![allow(
clippy::multiple_crate_versions, // syn 1 + 2, not currently avoidable
clippy::module_name_repetitions,
)]
#![cfg_attr(doc, warn(rustdoc::all))]
mod any;
mod components;
mod names;
mod style;
pub use any::AnyComponent;
#[doc(hidden)]
pub use names::IDENTIFIERS;
pub use names::{Identifier, Name, NameKey, StaticName};
#[cfg(feature = "derive")]
pub use stylecs_macros::StyleComponent;
pub use stylecs_shared::InvalidIdentifier;
pub use self::components::{DynamicComponent, StyleComponent};
pub use self::style::{Iter, Style};
#[doc(hidden)]
#[macro_export]
macro_rules! __count {
() => (0_usize);
( $x:tt $($xs:tt)* ) => (1_usize + $crate::__count!($($xs)*));
}
/// A shorthand for creating a [`Style`] type from a compile-time list of
/// [`StyleComponent`] implementors.
///
/// # Example Usage
///
/// ```rust
/// use stylecs::{style, StyleComponent};
///
/// #[derive(StyleComponent, Debug, Clone, Eq, PartialEq)]
/// struct SomeComponent(u32);
/// #[derive(StyleComponent, Debug, Clone)]
/// struct AnotherComponent;
///
/// let style = style![SomeComponent(42), AnotherComponent];
/// assert_eq!(style.len(), 2);
/// assert_eq!(style.get::<SomeComponent>(), Some(&SomeComponent(42)));
/// ```
#[macro_export]
macro_rules! style {
() => {
$crate::Style::new()
};
($($component:expr),+ $(,)?) => {{
let mut s = $crate::Style::with_capacity($crate::__count!($($component)+));
$(s.push($component);)+
s
}};
}
#[cfg(test)]
mod tests;