pub struct TemplateResolver { /* private fields */ }Expand description
Template resolver for gpack:template syntax
Implementations§
Source§impl TemplateResolver
impl TemplateResolver
Sourcepub fn new(
cache_manager: CacheManager,
lockfile_manager: LockfileManager,
) -> Self
pub fn new( cache_manager: CacheManager, lockfile_manager: LockfileManager, ) -> Self
Create a new template resolver
§Examples
use ggen_core::resolver::TemplateResolver;
use ggen_core::cache::CacheManager;
use ggen_core::lockfile::LockfileManager;
use std::path::Path;
let cache = CacheManager::new()?;
let lockfile = LockfileManager::new(Path::new("."));
let resolver = TemplateResolver::new(cache, lockfile);Sourcepub fn resolve(&self, template_ref: &str) -> Result<TemplateSource>
pub fn resolve(&self, template_ref: &str) -> Result<TemplateSource>
Resolve a template reference in the format “pack_id:template_path”
§Errors
Returns an error if:
- The template reference format is invalid (must be
pack_id:template_path) - The pack is not found in the lockfile
- The pack is not cached locally
- The template path doesn’t exist in the pack
- Path traversal is detected (e.g.,
../in template path)
§Examples
§Success case
use ggen_core::resolver::TemplateResolver;
use ggen_core::cache::CacheManager;
use ggen_core::lockfile::LockfileManager;
use std::path::Path;
let cache = CacheManager::new()?;
let lockfile = LockfileManager::new(Path::new("."));
let resolver = TemplateResolver::new(cache, lockfile);
// Resolve template reference
let source = resolver.resolve("io.ggen.rust.api:main.tmpl")?;
println!("Template at: {:?}", source.template_path);§Error case - Invalid format
use ggen_core::resolver::TemplateResolver;
use ggen_core::cache::CacheManager;
use ggen_core::lockfile::LockfileManager;
use std::path::Path;
let cache = CacheManager::new()?;
let lockfile = LockfileManager::new(Path::new("."));
let resolver = TemplateResolver::new(cache, lockfile);
// This will fail because the format is invalid (missing colon)
let result = resolver.resolve("invalid-format");
assert!(result.is_err());§Error case - Pack not found
use ggen_core::resolver::TemplateResolver;
use ggen_core::cache::CacheManager;
use ggen_core::lockfile::LockfileManager;
use std::path::Path;
let cache = CacheManager::new()?;
let lockfile = LockfileManager::new(Path::new("."));
let resolver = TemplateResolver::new(cache, lockfile);
// This will fail because the pack is not in the lockfile
let result = resolver.resolve("nonexistent.pack:template.tmpl");
assert!(result.is_err());Sourcepub fn search_templates(
&self,
query: Option<&str>,
) -> Result<Vec<TemplateSearchResult>>
pub fn search_templates( &self, query: Option<&str>, ) -> Result<Vec<TemplateSearchResult>>
Search for templates across all installed packs
§Example
use ggen_core::resolver::TemplateResolver;
use ggen_core::cache::CacheManager;
use ggen_core::lockfile::LockfileManager;
use std::path::Path;
let cache = CacheManager::new()?;
let lockfile = LockfileManager::new(Path::new("."));
let resolver = TemplateResolver::new(cache, lockfile);
// Search for templates containing "api"
let results = resolver.search_templates(Some("api"))?;
for result in results {
println!("Found: {}:{}", result.pack_id, result.template_path.display());
}Sourcepub fn get_pack_templates(&self, pack_id: &str) -> Result<Vec<String>>
pub fn get_pack_templates(&self, pack_id: &str) -> Result<Vec<String>>
Get available templates for a specific pack
Sourcepub fn get_template_info(&self, template_ref: &str) -> Result<TemplateInfo>
pub fn get_template_info(&self, template_ref: &str) -> Result<TemplateInfo>
Get template information including frontmatter
Trait Implementations§
Source§impl Clone for TemplateResolver
impl Clone for TemplateResolver
Source§fn clone(&self) -> TemplateResolver
fn clone(&self) -> TemplateResolver
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TemplateResolver
impl RefUnwindSafe for TemplateResolver
impl Send for TemplateResolver
impl Sync for TemplateResolver
impl Unpin for TemplateResolver
impl UnwindSafe for TemplateResolver
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request