CodecBuilder

Struct CodecBuilder 

Source
pub struct CodecBuilder { /* private fields */ }

Implementations§

Source§

impl CodecBuilder

Source

pub fn new() -> Self

Creates a new CodecBuilder with no resources.

Source

pub fn add_file<P: AsRef<Path>>(self, path: P) -> Result<Self, Error>

Adds a resource file by inferring its format from the file extension.

The language will be automatically inferred from the file path if possible. For example, en.lproj/Localizable.strings will be detected as English.

§Arguments
  • path - Path to the resource file
§Returns

Returns self for method chaining, or an Error if the file cannot be read.

Source

pub fn add_file_with_format<P: AsRef<Path>>( self, path: P, format_type: FormatType, ) -> Result<Self, Error>

Adds a resource file with a specific format and optional language override.

This method allows you to specify the format explicitly and optionally override the language that would be inferred from the file path.

§Arguments
  • path - Path to the resource file
  • format_type - The format type to use for parsing
§Returns

Returns self for method chaining, or an Error if the file cannot be read.

Source

pub fn read_file_by_extension<P: AsRef<Path>>( self, path: P, lang: Option<String>, ) -> Result<Self, Error>

Adds a resource file by inferring its format from the file extension with optional language override.

This method is similar to add_file but allows you to specify a language that will override any language inferred from the file path.

§Arguments
  • path - Path to the resource file
  • lang - Optional language code to use (overrides path inference)
§Returns

Returns self for method chaining, or an Error if the file cannot be read.

Source

pub fn add_resource(self, resource: Resource) -> Self

Adds a resource directly to the builder.

This method allows you to add a Resource instance directly, which is useful when you have resources that were created programmatically or loaded from other sources.

§Arguments
  • resource - The resource to add
§Returns

Returns self for method chaining.

Source

pub fn add_resources<I>(self, resources: I) -> Self
where I: IntoIterator<Item = Resource>,

Adds multiple resources directly to the builder.

This method allows you to add multiple Resource instances at once.

§Arguments
  • resources - Iterator of resources to add
§Returns

Returns self for method chaining.

Source

pub fn load_from_cache<P: AsRef<Path>>(self, path: P) -> Result<Self, Error>

Loads resources from a JSON cache file.

This method loads resources that were previously cached using Codec::cache_to_file.

§Arguments
  • path - Path to the JSON cache file
§Returns

Returns self for method chaining, or an Error if the file cannot be read.

Source

pub fn build(self) -> Codec

Builds the final Codec instance.

This method consumes the builder and returns the constructed Codec.

§Returns

Returns the constructed Codec instance.

Source

pub fn build_and_validate(self) -> Result<Codec, Error>

Builds the final Codec instance and validates it.

This method is similar to build() but performs additional validation on the resources before returning the Codec.

§Returns

Returns the constructed Codec instance, or an Error if validation fails.

Trait Implementations§

Source§

impl Default for CodecBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.