pub struct ModelsPath { /* private fields */ }Expand description
Validated model import path derived from a {service} template string.
Constructed once from CodeGenConfig template fields. resolve performs the
{service} substitution and parses the result as a syn::Path, catching
malformed templates at construction time rather than at code-generation time.
Implementations§
Source§impl ModelsPath
impl ModelsPath
Sourcepub fn new(template: &str) -> Result<Self>
pub fn new(template: &str) -> Result<Self>
Build a ModelsPath from a template string containing {service} and,
optionally, {version}.
Performs a test substitution at construction to validate the template.
Sourcepub fn try_resolve(&self, service: &str, version: &str) -> Result<Path>
pub fn try_resolve(&self, service: &str, version: &str) -> Result<Path>
Replace {service} with service and return the parsed syn::Path, erroring if the
substitution does not parse.
new only proves the template parses for the literal test; a real service segment that
isn’t a valid path component (leading digit, hyphen, reserved word) can still fail here.
Call this once per service up front (see ModelsPath::validate_for) so failures surface
as a clean Error::InvalidModelsPathTemplate before generation rather than panicking.
Sourcepub fn validate_for(&self, service: &str) -> Result<()>
pub fn validate_for(&self, service: &str) -> Result<()>
Validate that service substitutes into a parseable path. Used up front, per service.
Validates against the conventional v1 version; the actual version segment is a plain
path component derived from the proto package, so it cannot make a {service}-valid
template fail to parse.
Sourcepub fn resolve(&self, service: &str, version: &str) -> Path
pub fn resolve(&self, service: &str, version: &str) -> Path
Replace {service}/{version} and return the parsed syn::Path.
§Panics
Panics if the substituted path doesn’t parse. Generation validates every service segment
up front via ModelsPath::validate_for, so this is unreachable on the generation path;
prefer ModelsPath::try_resolve anywhere that hasn’t already validated.
Trait Implementations§
Source§impl Clone for ModelsPath
impl Clone for ModelsPath
Source§fn clone(&self) -> ModelsPath
fn clone(&self) -> ModelsPath
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ModelsPath
impl RefUnwindSafe for ModelsPath
impl Send for ModelsPath
impl Sync for ModelsPath
impl Unpin for ModelsPath
impl UnsafeUnpin for ModelsPath
impl UnwindSafe for ModelsPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more