eww_shared_util-0.1.0/.cargo_vcs_info.json0000644000000001640000000000100142200ustar { "git": { "sha1": "6f574e547adf4c35e660f2c1c7610eb74251d747" }, "path_in_vcs": "crates/eww_shared_util" }eww_shared_util-0.1.0/Cargo.toml0000644000000016020000000000100122140ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "eww_shared_util" version = "0.1.0" authors = ["elkowar <5300871+elkowar@users.noreply.github.com>"] description = "Utility crate used in eww" homepage = "https://github.com/elkowar/eww" license = "MIT" repository = "https://github.com/elkowar/eww" [dependencies.derive_more] version = "0.99" [dependencies.ref-cast] version = "1.0.6" [dependencies.serde] version = "1.0" features = ["derive"] eww_shared_util-0.1.0/Cargo.toml.orig000064400000000000000000000006040072674642500157260ustar 00000000000000[package] name = "eww_shared_util" version = "0.1.0" authors = ["elkowar <5300871+elkowar@users.noreply.github.com>"] edition = "2021" license = "MIT" description = "Utility crate used in eww" repository = "https://github.com/elkowar/eww" homepage = "https://github.com/elkowar/eww" [dependencies] serde = {version = "1.0", features = ["derive"]} derive_more = "0.99" ref-cast = "1.0.6" eww_shared_util-0.1.0/src/lib.rs000064400000000000000000000014620072674642500147450ustar 00000000000000pub mod span; pub mod wrappers; pub use span::*; pub use wrappers::*; #[macro_export] macro_rules! snapshot_debug { ( $($name:ident => $test:expr),* $(,)?) => { $( #[test] fn $name() { ::insta::assert_debug_snapshot!($test); } )* }; } #[macro_export] macro_rules! snapshot_string { ( $($name:ident => $test:expr),* $(,)?) => { $( #[test] fn $name() { ::insta::assert_snapshot!($test); } )* }; } #[macro_export] macro_rules! snapshot_ron { ( $($name:ident => $test:expr),* $(,)?) => { $( #[test] fn $name() { ::insta::with_settings!({sort_maps => true}, { ::insta::assert_ron_snapshot!($test); }); } )* }; } eww_shared_util-0.1.0/src/span.rs000064400000000000000000000033330072674642500151370ustar 00000000000000#[derive(Eq, PartialEq, Clone, Copy, serde::Serialize, serde::Deserialize)] pub struct Span(pub usize, pub usize, pub usize); impl Span { pub const DUMMY: Span = Span(usize::MAX, usize::MAX, usize::MAX); pub fn point(loc: usize, file_id: usize) -> Self { Span(loc, loc, file_id) } /// Get the span that includes this and the other span completely. /// Will panic if the spans are from different file_ids. pub fn to(mut self, other: Span) -> Self { assert!(other.2 == self.2); self.1 = other.1; self } pub fn ending_at(mut self, end: usize) -> Self { self.1 = end; self } /// Turn this span into a span only highlighting the point it starts at, setting the length to 0. pub fn point_span(mut self) -> Self { self.1 = self.0; self } /// Turn this span into a span only highlighting the point it ends at, setting the length to 0. pub fn point_span_at_end(mut self) -> Self { self.0 = self.1; self } pub fn shifted(mut self, n: isize) -> Self { self.0 = isize::max(0, self.0 as isize + n) as usize; self.1 = isize::max(0, self.0 as isize + n) as usize; self } pub fn is_dummy(&self) -> bool { *self == Self::DUMMY } } impl std::fmt::Display for Span { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if self.is_dummy() { write!(f, "DUMMY") } else { write!(f, "{}..{}", self.0, self.1) } } } impl std::fmt::Debug for Span { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) } } pub trait Spanned { fn span(&self) -> Span; } eww_shared_util-0.1.0/src/wrappers.rs000064400000000000000000000026700072674642500160440ustar 00000000000000use derive_more::*; use ref_cast::RefCast; use serde::{Deserialize, Serialize}; /// The name of a variable #[repr(transparent)] #[derive( Clone, Hash, PartialEq, Eq, Serialize, Deserialize, AsRef, From, FromStr, Display, DebugCustom, RefCast, )] #[debug(fmt = "VarName({})", .0)] pub struct VarName(pub String); impl std::borrow::Borrow for VarName { fn borrow(&self) -> &str { &self.0 } } impl AttrName { pub fn to_attr_name_ref(&self) -> &AttrName { AttrName::ref_cast(&self.0) } } impl From<&str> for VarName { fn from(s: &str) -> Self { VarName(s.to_owned()) } } impl From for VarName { fn from(x: AttrName) -> Self { VarName(x.0) } } /// The name of an attribute #[repr(transparent)] #[derive( Clone, Hash, PartialEq, Eq, Serialize, Deserialize, AsRef, From, FromStr, Display, DebugCustom, RefCast, )] #[debug(fmt="AttrName({})", .0)] pub struct AttrName(pub String); impl AttrName { pub fn to_var_name_ref(&self) -> &VarName { VarName::ref_cast(&self.0) } } impl std::borrow::Borrow for AttrName { fn borrow(&self) -> &str { &self.0 } } impl From<&str> for AttrName { fn from(s: &str) -> Self { AttrName(s.to_owned()) } } impl From for AttrName { fn from(x: VarName) -> Self { AttrName(x.0) } }