Module template
Processor for RFC 6570 URI Template.
Usage
- Prepare a template.
- You can create a template as
UriTemplateStrtype (borrowed) orUriTemplateStringtype (owned).
- You can create a template as
- Prepare a context.
- Create a value of type that implements
Contexttrait. - Or, if you use
SimpleContext, insert key-value pairs into it.
- Create a value of type that implements
- Expand.
- Pass the context to
UriTemplateStr::expandmethod of the template.
- Pass the context to
- Use the result.
- Returned
Expandedobject can be directly printed since it implements [Display]core::fmt::Displaytrait. Or, you can call.to_string()method of thealloc::string::ToStringtrait to convert it to aString.
- Returned
Examples
Custom context type
For details, see [the documentation of context module]context.
# use Error;
use fmt;
use ;
use UriTemplateStr;
use ;
let context = UserInfo ;
let template = new?;
#
# Ok::
SimpleContext type (enabled by alloc feature flag)
# use Error;
#
# Ok::
Modules
- context Template expansion context.
- simple_context Simple general-purpose context type.
Structs
- CreationError Error on conversion into a URI template type.
- Error Template construction and expansion error.
- Expanded Template expansion result.
- UriTemplateStr A borrowed slice of a URI template.
- UriTemplateString An owned slice of a URI template.
- UriTemplateVariables An iterator of variables in a URI template.
Traits
- Context A trait for types that can behave as a static URI template expansion context.
- DynamicContext A trait for types that can behave as a dynamic (mutable) URI template expansion context.
Type Aliases
-
VarName
Deprecated old name of
template::context::VarName.