Expand description
§Welcome to CCS2!
Let’s get started with an example to show some of the common use-cases. Given a file called
doc.ccs with the following contents:
a, f b e, c {
c d {
x = y
}
e f {
foobar = abc
}
}
x = 42… you may want to do something like this:
use ccs2::{Context, ToType};
let context = Context::logging("examples/configs/doc.ccs", log::Level::Info)?;
let constrained = context.constrain("a").constrain("c").constrain("d");
assert_eq!(&constrained.get_type::<String>("x")?, "y");
assert!(constrained.get("foobar").is_err());
// Original context is untouched:
assert_eq!(context.get("x")?.to_type::<i32>()?, 42);Example output (if logger is configured). Note that the actual origin will typically be absolute:
[2025-10-27T15:22:32Z INFO ccs2::tracer::log] Found property: x = y
in context: [ a > c > d ]
origin: examples/configs/doc.ccs:3
[2025-10-27T15:22:32Z INFO ccs2::tracer::log] Property not found: foobar
in context: [ a > c > d ]
[2025-10-27T15:22:32Z INFO ccs2::tracer::log] Found property: x = 42
in context: [ ]
origin: examples/configs/doc.ccs:10Most of the public API is in Context, so check there for a resonable starting point.
§Incomplete Requirements
The following requirements are not yet complete:
-
@importdoes not work; I still need to add support for import resolvers and filename tracking. -
The parser doesn’t track files right now, which isn’t great.
-
Log when a property could not be found, and when it’s ambiguous.
-
Support search with default value, which doesn’t return a
Result. -
String interpolation from environment variables (or whatever injected mapping)
-
ContextState::debug_contextprobably doesn’t correctly communicate@constrainor@contextstatements… Instead of a separate queue, we may want to compute it directly from the dag. -
stablechannel support: I’m currently onnightlyfor some oddthiserrorreasons, but I don’t think I should require that. I’ll need to figure that out. -
Opt-in Arc vs Rc context?
-
Much better error information for CCS syntax issues.
-
… Probably a bunch of other stuff, I’ll add to this as I think of things.
§Features
The crate provides the following features:
log(default): Adds theLogTracerfor logging when properties are found. Adds a dependency onlog.extra_conversions(default): Adds a parsers for gettingstd::time::Durationandstd::time::SystemTimefrom CCS property strings. Adds a dependency onchronoandhumantime.dot: Adds tools for exporting the underlying DAG todotsyntax, which allows for visualizing the context’s state. Adds a dependency onpetgraph.
Re-exports§
pub use crate::ast::AstError;pub use crate::ast::AstResult;pub use crate::ast::ImportResolver;pub use crate::ast::PersistentStr;pub use crate::ast::PropertyValue;pub use crate::dag::Stats as DagStats;
Modules§
Structs§
- Comma
Separated List - Splits at commas, and trims whitespace from both ends of resulting items
- Context
- The primary representation of a CCS search state
- Conversion
Failed - Occurs when parsing a string into a specific type fails
- Display
Context - Contains the constraints which have been applied to the current context. Formats nicely for debugging and logging.
- LogTracer
- A
PropertyTracerthat logs when and where properties are found - Null
Tracer - A
PropertyTracerthat does nothing - Relative
Path Resolver - The default import resolver, which resolves everything relative to one initial path
Enums§
- CcsError
- Slightly more flexible than
ContextError, as it also handles issues in parsing/interpreting - Context
Error - A common error type for code that tries to find and then convert a property
- IoError
- An error that occurs while reading a CCS file, before it gets parsed
- Search
Error - Represents a problem finding a property in the current context
Traits§
- AsKey
- A public-facing
Keyconverter, which allows creating a validKeyfor constraints - Clonable
Property Tracer - Property
Tracer - A callback which is called by the
Contextwhen a property is found - ToType
- A helper trait implemented by
PropertyValueto make string parsing/conversion easier - Typed
Property - Represents a type which can be created from a
PropertyValue