Crate ccs2

Crate ccs2 

Source
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:10

Most of the public API is in Context, so check there for a resonable starting point.

§Incomplete Requirements

The following requirements are not yet complete:

  • @import does 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_context probably doesn’t correctly communicate @constrain or @context statements… Instead of a separate queue, we may want to compute it directly from the dag.

  • stable channel support: I’m currently on nightly for some odd thiserror reasons, 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 the LogTracer for logging when properties are found. Adds a dependency on log.
  • extra_conversions (default): Adds a parsers for getting std::time::Duration and std::time::SystemTime from CCS property strings. Adds a dependency on chrono and humantime.
  • dot: Adds tools for exporting the underlying DAG to dot syntax, which allows for visualizing the context’s state. Adds a dependency on petgraph.

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§

ast
dag

Structs§

CommaSeparatedList
Splits at commas, and trims whitespace from both ends of resulting items
Context
The primary representation of a CCS search state
ConversionFailed
Occurs when parsing a string into a specific type fails
DisplayContext
Contains the constraints which have been applied to the current context. Formats nicely for debugging and logging.
LogTracer
A PropertyTracer that logs when and where properties are found
NullTracer
A PropertyTracer that does nothing
RelativePathResolver
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
ContextError
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
SearchError
Represents a problem finding a property in the current context

Traits§

AsKey
A public-facing Key converter, which allows creating a valid Key for constraints
ClonablePropertyTracer
PropertyTracer
A callback which is called by the Context when a property is found
ToType
A helper trait implemented by PropertyValue to make string parsing/conversion easier
TypedProperty
Represents a type which can be created from a PropertyValue

Type Aliases§

CcsResult
ContextResult
ConversionResult
IoResult
SearchResult