Skip to main content

ModelNaming

Trait ModelNaming 

Source
pub trait ModelNaming {
    // Provided methods
    fn model_name() -> ModelName { ... }
    fn model_name_instance(&self) -> ModelName { ... }
    fn to_model(&self) -> &Self { ... }
    fn singular(&self) -> String { ... }
    fn plural(&self) -> String { ... }
    fn route_key(&self) -> String { ... }
    fn singular_route_key(&self) -> String { ... }
    fn param_key(&self) -> String { ... }
    fn uncountable() -> bool { ... }
    fn human_attribute_name(attribute: &str) -> String { ... }
}
Expand description

Model naming conventions shared across model-like types.

Override ModelNaming::model_name when a type needs custom naming metadata, such as namespaced routing or a non-standard external name.

Provided Methods§

Source

fn model_name() -> ModelName

Returns cached naming metadata for the implementing type.

Source

fn model_name_instance(&self) -> ModelName

Returns cached naming metadata from an instance.

Source

fn to_model(&self) -> &Self

Mirrors Rails’ to_model naming helper for already-materialized records.

Source

fn singular(&self) -> String

Returns the singular key for a record instance.

Source

fn plural(&self) -> String

Returns the plural key for a record instance.

Source

fn route_key(&self) -> String

Returns the route collection key for a record instance.

Source

fn singular_route_key(&self) -> String

Returns the singular route key for a record instance.

Source

fn param_key(&self) -> String

Returns the URL parameter key for a record instance.

Source

fn uncountable() -> bool

Returns true when the model name is uncountable.

Source

fn human_attribute_name(attribute: &str) -> String

Returns a human-readable label for an attribute name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§