### Typical Usage Example Source: https://docs.rs/hashavatar/0.3.0/hashavatar Demonstrates the typical usage of the hashavatar crate for generating an avatar image for a given identifier. ```APIDOC ## encode_avatar_for_id Example ### Description This example shows how to use the `encode_avatar_for_id` function to generate a WebP avatar image for a given email address with specific options. ### Function `encode_avatar_for_id` ### Parameters - `spec` (AvatarSpec) - Specifies the dimensions and style version of the avatar. - `id` (string) - The identifier string to generate the avatar from. - `format` (AvatarOutputFormat) - The desired output format for the avatar (e.g., WebP). - `options` (AvatarOptions) - Options for avatar kind and background. ### Request Example ```rust use hashavatar::{ AvatarBackground, AvatarKind, AvatarOptions, AvatarOutputFormat, AvatarSpec, encode_avatar_for_id, }; let bytes = encode_avatar_for_id( AvatarSpec::new(256, 256, 0), "alice@example.com", AvatarOutputFormat::WebP, AvatarOptions { kind: AvatarKind::Robot, background: AvatarBackground::White, }, )?; ``` ### Response - `bytes` (Vec) - A byte vector containing the encoded avatar image. ``` -------------------------------- ### HashAvatar Usage Example Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Demonstrates how to generate an avatar for a given identifier using the `encode_avatar_for_id` function. ```APIDOC ## HashAvatar Usage Example ### Description This example shows how to generate a deterministic avatar image from an input identifier using the `hashavatar` crate. It utilizes `encode_avatar_for_id` with specified dimensions, output format, and avatar options. ### Method `encode_avatar_for_id` ### Endpoint N/A (Rust function) ### Parameters - **`spec`** (AvatarSpec) - Required - Specifies the dimensions (width, height) and seed for the avatar. - **`id`** (string) - Required - The input identifier (e.g., email address) to generate the avatar from. - **`format`** (AvatarOutputFormat) - Required - The desired output format for the avatar image (e.g., WebP, PNG). - **`options`** (AvatarOptions) - Required - Options to customize the avatar's appearance, including `kind` (e.g., Robot) and `background` (e.g., White). ### Request Example ```rust use hashavatar::{ AvatarBackground, AvatarKind, AvatarOptions, AvatarOutputFormat, AvatarSpec, encode_avatar_for_id, }; let bytes = encode_avatar_for_id( AvatarSpec::new(256, 256, 0), "alice@example.com", AvatarOutputFormat::WebP, AvatarOptions { kind: AvatarKind::Robot, background: AvatarBackground::White, }, )?; ``` ### Response #### Success Response (bytes) - **`bytes`** (Vec) - The generated avatar image data in the specified format. #### Response Example (Binary image data, not representable as JSON) ``` -------------------------------- ### AvatarOutputFormat Enum Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Specifies export formats for encoded avatar assets. `WebP` is the default due to its modern nature and typically smaller file sizes compared to PNG for generated avatar art. Use `ALL` to get all available formats and `as_str` to get the string representation. ```rust #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum AvatarOutputFormat { #[default] WebP, Png, } impl AvatarOutputFormat { pub const ALL: [Self; 2] = [Self::WebP, Self::Png]; pub const fn as_str(self) -> &'static str { match self { Self::WebP => "webp", Self::Png => "png", } } } ``` ```rust impl FromStr for AvatarOutputFormat { type Err = &'static str; fn from_str(s: &str) -> Result { match s.trim().to_ascii_lowercase().as_str() { "webp" => Ok(Self::WebP), "png" => Ok(Self::Png), _ => Err("unsupported avatar output format"), } } } ``` ```rust impl std::fmt::Display for AvatarOutputFormat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(self.as_str()) } } ``` -------------------------------- ### Get Avatar Identity Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedCatAvatar.html Retrieves a reference to the AvatarIdentity associated with the HashedCatAvatar. ```rust pub fn identity(&self) -> &AvatarIdentity ``` -------------------------------- ### HashedDogAvatar Initialization Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedDogAvatar.html Methods to instantiate a new HashedDogAvatar instance. ```APIDOC ## HashedDogAvatar::new ### Description Creates a new HashedDogAvatar instance from input data and a background specification. ### Parameters - **input** (T: AsRef<[u8]>) - Required - The input data to hash for the avatar. - **background** (AvatarBackground) - Required - The background configuration for the avatar. ## HashedDogAvatar::new_with_namespace ### Description Creates a new HashedDogAvatar instance using a specific namespace, input data, and background specification. ### Parameters - **namespace** (AvatarNamespace) - Required - The namespace for the avatar generation. - **input** (T: AsRef<[u8]>) - Required - The input data to hash for the avatar. - **background** (AvatarBackground) - Required - The background configuration for the avatar. ``` -------------------------------- ### Get SHA-512 Digest Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarIdentity.html Returns a reference to the 64-byte SHA-512 digest associated with the AvatarIdentity. ```rust pub const fn as_digest(&self) -> &[u8; 64] ``` -------------------------------- ### HashedRobotAvatar Constructor Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedRobotAvatar.html Methods to initialize a new HashedRobotAvatar instance. ```APIDOC ## Constructor: new ### Description Creates a new HashedRobotAvatar instance from input data and a background specification. ### Parameters - **input** (T: AsRef<[u8]>) - Required - The input data to hash for the avatar. - **background** (AvatarBackground) - Required - The background configuration for the avatar. ## Constructor: new_with_namespace ### Description Creates a new HashedRobotAvatar instance using a specific namespace, input data, and background. ### Parameters - **namespace** (AvatarNamespace<'_>) - Required - The namespace for the avatar generation. - **input** (T: AsRef<[u8]>) - Required - The input data to hash. - **background** (AvatarBackground) - Required - The background configuration. ``` -------------------------------- ### Get Type ID of a Value Source: https://docs.rs/hashavatar/0.3.0/hashavatar/enum.AvatarBackground.html Retrieves the `TypeId` of a value. This is a blanket implementation for any type that is 'static. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Initialize ImageBuffer and Define Colors Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Initializes a new image buffer with a white background and defines several color constants based on input identity values. These colors are used for different parts of the avatar. ```rust let mut image = ImageBuffer::from_pixel(spec.width, spec.height, Color::rgb(255, 255, 255).into()); let skin = hsl_to_color( identity.unit_f32(0) * 360.0, 0.48 + identity.unit_f32(1) * 0.24, 0.46 + identity.unit_f32(2) * 0.20, ); let shade = hsl_to_color( identity.unit_f32(3) * 360.0, 0.38 + identity.unit_f32(4) * 0.18, 0.24 + identity.unit_f32(5) * 0.10, ); let accent = hsl_to_color( 20.0 + identity.unit_f32(6) * 320.0, 0.34 + identity.unit_f32(7) * 0.26, 0.86, ); let mouth = Color::rgb(48, 18, 24); let eye_white = Color::rgb(252, 248, 236); let pupil = Color::rgb(24, 20, 28); ``` -------------------------------- ### Draw Mouth (Default Style) using draw_filled_rect_mut and draw_polygon_mut Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Renders a simple rectangular mouth with optional teeth using `draw_filled_rect_mut` and `draw_polygon_mut`. ```rust draw_filled_rect_mut( &mut image, Rect::at(center_x - head_rx / 3, mouth_y - head_ry / 10).of_size( (head_rx * 2 / 3) as u32, (head_ry / 5).max(1) as u32, ), mouth.into(), ); ``` ```rust draw_polygon_mut( &mut image, &[ Point::new(tooth_x - head_rx / 30, mouth_y - head_ry / 10), Point::new(tooth_x + head_rx / 30, mouth_y - head_ry / 10), Point::new(tooth_x, mouth_y + head_ry / 14), ], eye_white.into(), ); ``` -------------------------------- ### Create New AvatarNamespace Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarNamespace.html Constructor for AvatarNamespace. Initializes a new instance with the provided tenant and style version. ```rust pub const fn new(tenant: &'a str, style_version: &'a str) -> Self ``` -------------------------------- ### Get Seed Value Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarIdentity.html Retrieves a u64 seed value derived from the AvatarIdentity. This seed can be used for generating visual parameters. ```rust pub fn seed(&self) -> u64 ``` -------------------------------- ### TryComponentsInto for T Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedRobotAvatar.html Attempts to convert a collection of color components into a collection of colors. ```APIDOC ## impl TryComponentsInto for T ### Description Try to cast this collection of color components into a collection of colors. ### Method `try_components_into` ### Parameters None ### Request Body None ### Response #### Success Response (200) - **C** (type) - The collection of colors if conversion is successful. #### Error Response - **Error** (type) - The error type returned by `TryFromComponents`. #### Response Example ```json { "example": "Result" } ``` ``` -------------------------------- ### Get All AvatarBackground Variants Source: https://docs.rs/hashavatar/0.3.0/hashavatar/enum.AvatarBackground.html Provides a static array containing all possible variants of the AvatarBackground enum. Useful for iteration or initialization. ```rust pub const ALL: [Self; 2] ``` -------------------------------- ### Color Utilities Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Helper functions for color space conversion and formatting. ```rust fn hsl_to_color(hue: f32, saturation: f32, lightness: f32) -> Color { let rgb_u8: Srgb = Srgb::from_color(Hsl::new(hue, saturation, lightness)).into_format(); Color::rgb(rgb_u8.red, rgb_u8.green, rgb_u8.blue) } ``` ```rust fn background_fill(background: AvatarBackground, themed: Color) -> Color { match background { AvatarBackground::Themed => themed, AvatarBackground::White => Color::rgb(255, 255, 255), } } ``` ```rust fn color_hex(color: Color) -> String { format!("#{:02x}{:02x}{:02x}", color.0[0], color.0[1], color.0[2]) } ``` -------------------------------- ### Render Robot Avatar SVG Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Initializes parameters for generating a robot avatar SVG. ```rust fn render_robot_svg(spec: AvatarSpec, identity: &AvatarIdentity) -> String { let w = spec.width as f32; let h = spec.height as f32; let cx = w / 2.0; let cy = h * 0.56; let metal = hsl_to_color(205.0 + identity.unit_f32(3) * 25.0, 0.16, 0.74); let trim = hsl_to_color(205.0 + identity.unit_f32(4) * 22.0, 0.18, 0.46); let light = hsl_to_color(60.0 + identity.unit_f32(5) * 110.0, 0.78, 0.66); let head_w = w * 0.48; let head_h = h * 0.38; let x = cx - head_w / 2.0; let y = cy - head_h / 2.0; format!( ``` -------------------------------- ### TryComponentsInto and TryFromTraits Source: https://docs.rs/hashavatar/0.3.0/hashavatar/enum.AvatarKind.html These traits facilitate fallible conversions. `TryComponentsInto` attempts to convert color components, while `TryFrom` and `TryInto` are general-purpose fallible conversions. ```APIDOC ## TryComponentsInto for T ### Description Attempts to convert a collection of color components into a collection of colors. ### Type Alias - **Error** (>::Error) - The error type returned if the conversion fails. ### Method `try_components_into(self) -> Result>::Error>` ### Endpoint N/A (Trait method) ### Parameters None ### Request Example N/A ### Response #### Success Response (Ok) Returns the converted collection of colors `C`. #### Response Example N/A ## TryFrom for T ### Description Provides a fallible way to convert type `U` into type `T`. ### Type Alias - **Error** (Infallible) - The error type returned if the conversion fails (in this specific case, it's `Infallible`, meaning it never fails). ### Method `try_from(value: U) -> Result>::Error>` ### Description Performs the conversion. ### Endpoint N/A (Trait method) ### Parameters - **value** (U) - The value to convert. ### Request Example N/A ### Response #### Success Response (Ok) Returns an instance of type `T`. #### Response Example N/A ## TryInto for T ### Description Provides a fallible way to convert type `T` into type `U`. ### Type Alias - **Error** (>::Error) - The error type returned if the conversion fails. ### Method `try_into(self) -> Result>::Error>` ### Description Performs the conversion. ### Endpoint N/A (Trait method) ### Parameters None ### Request Example N/A ### Response #### Success Response (Ok) Returns an instance of type `U`. #### Response Example N/A ``` -------------------------------- ### Encode Avatar to WebP Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Demonstrates encoding an avatar to WebP format and verifying the output dimensions. ```rust #[test] fn generic_avatar_encoder_supports_robot_and_white_background() { let bytes = encode_avatar_for_id( AvatarSpec::new(96, 96, 0), "robot@example.com", AvatarOutputFormat::WebP, AvatarOptions { kind: AvatarKind::Robot, background: AvatarBackground::White, }, ) .expect("robot webp encoding should succeed"); let decoded = image::load_from_memory_with_format(&bytes, ImageFormat::WebP) .expect("robot webp should decode"); assert_eq!(decoded.width(), 96); assert_eq!(decoded.height(), 96); } ``` -------------------------------- ### HashedCatAvatar Initialization Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedCatAvatar.html Methods for creating a new HashedCatAvatar instance from input data. ```APIDOC ## HashedCatAvatar::new ### Description Creates a new HashedCatAvatar instance from the provided input. ### Parameters #### Path Parameters - **input** (T: AsRef<[u8]>) - Required - The input data used to generate the avatar identity. ## HashedCatAvatar::new_with_namespace ### Description Creates a new HashedCatAvatar instance using a specific namespace and input. ### Parameters #### Path Parameters - **namespace** (AvatarNamespace) - Required - The namespace for the avatar. - **input** (T: AsRef<[u8]>) - Required - The input data used to generate the avatar identity. ``` -------------------------------- ### Same for T Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedRobotAvatar.html Defines an associated type `Output` that should always be `Self`. ```APIDOC ## impl Same for T ### Description Should always be `Self`. ### Method Associated Type ### Parameters None ### Request Body None ### Response #### Success Response (200) - **Output** (type) - Should always be `Self`. #### Response Example ```json { "example": "Self" } ``` ``` -------------------------------- ### Render Avatar for Namespace Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Renders an avatar for a given namespace, ID, and options directly as an image. ```APIDOC ## POST /api/avatar/render ### Description Renders an avatar for a given namespace, ID, and options directly as an image. ### Method POST ### Endpoint /api/avatar/render ### Parameters #### Request Body - **spec** (AvatarSpec) - Required - The avatar specification. - **namespace** (AvatarNamespace) - Required - The namespace for the avatar. - **id** (T: AsRef<[u8]>) - Required - The identifier for the avatar. - **options** (AvatarOptions) - Required - Options for rendering the avatar. ### Request Example ```json { "spec": {"size": 128, "border_radius": 0.5}, "namespace": "default", "id": "user123", "options": {"kind": "dog", "background": "#000000"} } ``` ### Response #### Success Response (200) - **image** (RgbaImage) - The rendered avatar image. #### Response Example ```json { "image": "image_data_representation" } ``` ``` -------------------------------- ### New HashedCatAvatar with Namespace Constructor Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedCatAvatar.html Creates a new HashedCatAvatar instance with a specified namespace and input. The input must be convertible to a byte slice. ```rust pub fn new_with_namespace>( namespace: AvatarNamespace<'_>, input: T, ) -> Self ``` -------------------------------- ### IntoCam16Unclamped Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedRobotAvatar.html Converts a color into `C` using provided parameters, without clamping. ```APIDOC ## fn into_cam16_unclamped( self, parameters: BakedParameters>::Scalar>, ) -> T ### Description Converts `self` into `C`, using the provided parameters. The resulting color might be invalid in its color space. ### Method `into_cam16_unclamped` ### Parameters - **parameters** (BakedParameters>::Scalar>) - The parameters for conversion. ### Request Body None ### Response #### Success Response (200) - **T** (type) - The converted color. #### Response Example ```json { "example": "converted_color" } ``` ``` -------------------------------- ### TryComponentsInto Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarOptions.html Attempts to cast a collection of color components into a collection of colors, returning a `Result` that indicates success or failure. ```APIDOC ## impl TryComponentsInto for T where C: TryFromComponents, ### Description Attempts to cast a collection of color components into a collection of colors. ### Associated Type `Error = >::Error` - The error type for when `try_into_colors` fails. ### Method `try_components_into(self) -> Result>::Error>` Try to cast this collection of color components into a collection of colors. Read more ``` -------------------------------- ### Draw Mouth (Style 0) using draw_filled_ellipse_mut and draw_polygon_mut Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Renders a mouth shape using an ellipse and two triangular fangs. Uses `draw_filled_ellipse_mut` and `draw_polygon_mut`. ```rust draw_filled_ellipse_mut( &mut image, (center_x, mouth_y), head_rx / 3, head_ry / 8, mouth.into(), ); ``` ```rust draw_polygon_mut( &mut image, &[ Point::new(fang_x - head_rx / 24, mouth_y - 2), Point::new(fang_x + head_rx / 24, mouth_y - 2), Point::new(fang_x, mouth_y + head_ry / 5), ], eye_white.into(), ); ``` -------------------------------- ### Draw Mouth (Style 1) using draw_smile_arc and draw_line_segment_mut Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Creates a smiling mouth using two arcs and a connecting line segment. Utilizes `draw_smile_arc` and `draw_line_segment_mut`. ```rust draw_smile_arc( &mut image, center_x - head_rx / 10, mouth_y, head_rx / 4, mouth, 0.50, ); ``` ```rust draw_smile_arc( &mut image, center_x + head_rx / 10, mouth_y, head_rx / 4, mouth, 0.50, ); ``` ```rust draw_line_segment_mut( &mut image, ((center_x - head_rx / 4) as f32, mouth_y as f32), ((center_x + head_rx / 4) as f32, mouth_y as f32), mouth.into(), ); ``` -------------------------------- ### Color Struct Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.Color.html Documentation for the RGBA color helper struct. ```APIDOC ## Struct Color ### Summary RGBA color helper for concise shape drawing. ### Tuple Fields * `0: [u8; 4]` - Represents the RGBA color components. ### Implementations #### impl Color ##### pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self Creates a new Color instance with the given RGBA values. ##### pub const fn rgb(r: u8, g: u8, b: u8) -> Self Creates a new Color instance with the given RGB values and full alpha. ### Trait Implementations #### impl Clone for Color ##### fn clone(&self) -> Color Returns a duplicate of the value. ##### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. #### impl Debug for Color ##### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. #### impl From for Rgba ##### fn from(value: Color) -> Self Converts to this type from the input type. #### impl PartialEq for Color ##### fn eq(&self, other: &Color) -> bool Tests for `self` and `other` values to be equal. ##### fn ne(&self, other: &Rhs) -> bool Tests for `!=`. #### impl Copy for Color #### impl Eq for Color #### impl StructuralPartialEq for Color ### Auto Trait Implementations * Freeze * RefUnwindSafe * Send * Sync * Unpin * UnsafeUnpin * UnwindSafe ### Blanket Implementations #### impl AdaptInto for S ##### fn adapt_into_using(self, method: M) -> D Converts the source color to the destination color using the specified method. ##### fn adapt_into(self) -> D Convert the source color to the destination color using the bradford method by default. #### impl Any for T ##### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. #### impl ArraysFrom for T ##### fn arrays_from(colors: C) -> T Cast a collection of colors into a collection of arrays. #### impl ArraysInto for T ##### fn arrays_into(self) -> C Cast this collection of arrays into a collection of colors. #### impl Borrow for T ##### fn borrow(&self) -> &T Immutably borrows from an owned value. #### impl BorrowMut for T ##### fn borrow_mut(&mut self) -> &mut T Mutably borrows from an owned value. #### impl Cam16IntoUnclamped for U ##### type Scalar = >::Scalar The number type that’s used in `parameters` when converting. ##### fn cam16_into_unclamped( self, parameters: BakedParameters>::Scalar>, ) -> T Converts `self` into `C`, using the provided parameters. #### impl CloneToUninit for T ##### unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. #### impl ComponentsFrom for T ##### fn components_from(colors: C) -> T Cast a collection of colors into a collection of color components. #### impl From for T ##### fn from(t: T) -> T Returns the argument unchanged. #### impl FromAngle for T ##### fn from_angle(angle: T) -> T Performs a conversion from `angle`. #### impl FromStimulus for T ##### fn from_stimulus(other: U) -> T Converts `other` into `Self`, while performing the appropriate scaling, rounding and clamping. #### impl Into for T ##### fn into(self) -> U Calls `U::from(self)`. #### impl IntoAngle for T ##### fn into_angle(self) -> U Performs a conversion into `T`. #### impl IntoCam16Unclamped for U ##### type Scalar = >::Scalar The number type that’s used in `parameters` when converting. ``` -------------------------------- ### TryFrom Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarOptions.html Provides a fallible conversion from one type into another, returning a `Result` with either the converted value or an error. ```APIDOC ## impl TryFrom for T where U: Into, ### Description Provides a fallible conversion from one type into another. ### Associated Type `Error = Infallible` - The type returned in the event of a conversion error. ### Method `try_from(value: U) -> Result>::Error>` Performs the conversion. ``` -------------------------------- ### AvatarNamespace Implementations Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarNamespace.html Details various implementations for the AvatarNamespace struct, including Clone, Debug, Default, PartialEq, Copy, and Eq. ```APIDOC ## Implementations for AvatarNamespace ### `impl<'a> Clone for AvatarNamespace<'a>` - `fn clone(&self) -> AvatarNamespace<'a>`: Returns a duplicate of the value. - `fn clone_from(&mut self, source: &Self)`: Performs copy-assignment from `source`. ### `impl<'a> Debug for AvatarNamespace<'a>` - `fn fmt(&self, f: &mut Formatter<'_>) -> Result`: Formats the value using the given formatter. ### `impl Default for AvatarNamespace<'_>` - `fn default() -> Self`: Returns the “default value” for a type. ### `impl<'a> PartialEq for AvatarNamespace<'a>` - `fn eq(&self, other: &AvatarNamespace<'a>) -> bool`: Tests for `self` and `other` values to be equal. - `fn ne(&self, other: &Rhs) -> bool`: Tests for `!=`. ### `impl<'a> Copy for AvatarNamespace<'a>` ### `impl<'a> Eq for AvatarNamespace<'a>` ### `impl<'a> StructuralPartialEq for AvatarNamespace<'a>` ``` -------------------------------- ### Color and AvatarSpec Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Documentation for `Color` struct and `AvatarSpec` for defining avatar properties. ```APIDOC ## Color and AvatarSpec ### Description These structs define the basic building blocks for avatar generation: `Color` for RGBA values and `AvatarSpec` for image dimensions and seeding. ### Color Struct #### Description Represents an RGBA color with convenient constructors. #### Fields - **`rgba(r, g, b, a)`** (const fn) - Creates a `Color` from RGBA values. - **`rgb(r, g, b)`** (const fn) - Creates an opaque `Color` from RGB values. ### AvatarSpec Struct #### Description Defines the specifications for an avatar image, including its dimensions and a seed for deterministic generation. #### Fields - **`width`** (u32) - The width of the avatar image. - **`height`** (u32) - The height of the avatar image. - **`seed`** (u64) - A seed value used for deterministic generation. #### Methods - **`new(width, height, seed)`** (const fn) - Creates a new `AvatarSpec`. - **`default()`** (impl Default) - Provides a default `AvatarSpec` (256x256, seed 1). ``` -------------------------------- ### TryInto Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarOptions.html Provides a fallible conversion from `self` into another type `U`, returning a `Result` that indicates success or failure. ```APIDOC ## impl TryInto for T where U: TryFrom, ### Description Provides a fallible conversion from `self` into another type `U`. ### Associated Type `Error = >::Error` - The type returned in the event of a conversion error. ### Method `try_into(self) -> Result>::Error>` Performs the conversion. ``` -------------------------------- ### Adapt Color Using Default Method Source: https://docs.rs/hashavatar/0.3.0/hashavatar/enum.AvatarBackground.html Converts the source color to the destination color using the Bradford method by default. This is a blanket implementation for color adaptation. ```rust fn adapt_into(self) -> D ``` -------------------------------- ### Render Robot Avatar Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Initializes a canvas and draws a robot-style avatar using geometric shapes and color palettes derived from an identity. ```rust pub fn render_robot_avatar_for_identity( spec: AvatarSpec, identity: &AvatarIdentity, background: AvatarBackground, ) -> RgbaImage { assert!(spec.width >= 64, "width must be at least 64 pixels"); assert!(spec.height >= 64, "height must be at least 64 pixels"); let width = spec.width as i32; let height = spec.height as i32; let mut image = ImageBuffer::from_pixel(spec.width, spec.height, Color::rgb(255, 255, 255).into()); let center_x = width / 2; let center_y = (height as f32 * 0.56) as i32; let bg = hsl_to_color( 210.0 + identity.unit_f32(0) * 70.0, 0.18 + identity.unit_f32(1) * 0.18, 0.92, ); let accent = hsl_to_color(160.0 + identity.unit_f32(2) * 120.0, 0.48, 0.62); let metal = hsl_to_color(200.0 + identity.unit_f32(3) * 28.0, 0.16, 0.74); let trim = hsl_to_color(205.0 + identity.unit_f32(4) * 22.0, 0.18, 0.46); let light = hsl_to_color(50.0 + identity.unit_f32(5) * 120.0, 0.84, 0.66); let dark = Color::rgb(47, 60, 72); let bg_fill = background_fill(background, bg); image.pixels_mut().for_each(|pixel| *pixel = bg_fill.into()); let head_w = (width as f32 * (0.44 + identity.unit_f32(6) * 0.12)) as i32; let head_h = (height as f32 * (0.34 + identity.unit_f32(7) * 0.10)) as i32; let head_x = center_x - head_w / 2; let head_y = center_y - head_h / 2; draw_background_accent( &mut image, center_x, center_y, head_w / 2, head_h / 2, accent, 0.5, background, ); draw_filled_rect_mut( &mut image, Rect::at(head_x, head_y).of_size(head_w as u32, head_h as u32), metal.into(), ); draw_line_segment_mut( &mut image, (head_x as f32, head_y as f32), ((head_x + head_w) as f32, head_y as f32), trim.into(), ); draw_line_segment_mut( &mut image, (head_x as f32, (head_y + head_h) as f32), ((head_x + head_w) as f32, (head_y + head_h) as f32), trim.into(), ); draw_line_segment_mut( &mut image, (head_x as f32, head_y as f32), (head_x as f32, (head_y + head_h) as f32), trim.into(), ); draw_line_segment_mut( &mut image, ``` -------------------------------- ### Render Cat SVG Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Initializes dimensions and colors for SVG cat avatar generation. ```rust fn render_cat_svg(spec: AvatarSpec, identity: &AvatarIdentity) -> String { let w = spec.width as f32; let h = spec.height as f32; let cx = w / 2.0; let cy = h * 0.56; let rx = w * (0.26 + identity.unit_f32(20) * 0.07); let ry = h * (0.22 + identity.unit_f32(21) * 0.08); let head = hsl_to_color(20.0 + identity.unit_f32(0) * 40.0, 0.48, 0.64); let muzzle = hsl_to_color(28.0 + identity.unit_f32(1) * 18.0, 0.18, 0.90); let eye = hsl_to_color(90.0 + identity.unit_f32(2) * 40.0, 0.7, 0.55); let outline = Color::rgb(64, 45, 32); let left_ear = format!( "{},{} {},{} {},{}", ``` -------------------------------- ### Create New AvatarSpec Instance Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarSpec.html Constructor for creating a new AvatarSpec instance with specified dimensions and seed. ```rust pub const fn new(width: u32, height: u32, seed: u64) -> Self ``` -------------------------------- ### UintsFrom and UintsInto Traits Source: https://docs.rs/hashavatar/0.3.0/hashavatar/enum.AvatarKind.html These traits handle conversions between color collections and collections of unsigned integers. ```APIDOC ## UintsFrom for U ### Description Casts a collection of colors `C` into a collection of unsigned integers `U`. ### Method `uints_from(colors: C) -> U` ### Endpoint N/A (Trait method) ### Parameters - **colors** (C) - The collection of colors to convert. ### Request Example N/A ### Response #### Success Response Returns a collection of unsigned integers `U`. #### Response Example N/A ## UintsInto for U ### Description Casts a collection of unsigned integers `U` into a collection of colors `C`. ### Method `uints_into(self) -> C` ### Endpoint N/A (Trait method) ### Parameters None ### Request Example N/A ### Response #### Success Response Returns a collection of colors `C`. #### Response Example N/A ``` -------------------------------- ### Component and Subset Operations Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedCatAvatar.html Utilities for casting color components and managing subset/superset relationships. ```APIDOC ## TryComponentsInto ### Description Attempts to cast a collection of color components into a collection of colors. ### Method Trait Method ### Response - **Result** - Returns the converted collection or an error if the cast fails. ## SupersetOf ### Description Provides methods for mapping between supersets and subsets of color data. ### Method Trait Methods ### Parameters - **to_subset** - Attempts to construct a subset from a superset. - **from_subset** - Converts a subset to a superset. ``` -------------------------------- ### Render Avatar for Namespace Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Renders an avatar image directly for a given namespace, ID, and options. Selects the appropriate rendering function based on the avatar kind specified in options. ```rust pub fn render_avatar_for_namespace>( spec: AvatarSpec, namespace: AvatarNamespace<'_>, id: T, options: AvatarOptions, ) -> RgbaImage { let identity = AvatarIdentity::new_with_namespace(namespace, id); match options.kind { AvatarKind::Cat => { render_cat_avatar_for_identity_with_background(spec, &identity, options.background) } AvatarKind::Dog => render_dog_avatar_for_identity(spec, &identity, options.background), AvatarKind::Robot => render_robot_avatar_for_identity(spec, &identity, options.background), AvatarKind::Fox => render_fox_avatar_for_identity(spec, &identity, options.background), AvatarKind::Alien => render_alien_avatar_for_identity(spec, &identity, options.background), AvatarKind::Monster => { render_monster_avatar_for_identity(spec, &identity, options.background) } AvatarKind::Ghost => render_ghost_avatar_for_identity(spec, &identity, options.background), AvatarKind::Slime => render_slime_avatar_for_identity(spec, &identity, options.background), AvatarKind::Bird => render_bird_avatar_for_identity(spec, &identity, options.background), AvatarKind::Wizard => { render_wizard_avatar_for_identity(spec, &identity, options.background) } AvatarKind::Skull => render_skull_avatar_for_identity(spec, &identity, options.background), AvatarKind::Paws => render_paws_avatar_for_identity(spec, &identity, options.background), } } ``` -------------------------------- ### UintsFrom for U Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.HashedRobotAvatar.html Casts a collection of colors into a collection of unsigned integers. ```APIDOC ## impl UintsFrom for U ### Description Cast a collection of colors into a collection of unsigned integers. ### Method `uints_from` ### Parameters - **colors** (C) - The collection of colors to cast. ### Request Body None ### Response #### Success Response (200) - **U** (type) - The collection of unsigned integers. #### Response Example ```json { "example": "uint_collection" } ``` ``` -------------------------------- ### Implement AdaptInto for Generic Type S Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.CatAvatar.html Provides a generic implementation of AdaptInto for type S, allowing conversion to type D using a specified method or default. ```rust fn adapt_into_using(self, method: M) -> D where M: TransformMatrix, ``` ```rust fn adapt_into(self) -> D ``` -------------------------------- ### Render Fox Avatar Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Initializes the canvas and draws the fox avatar based on identity-derived color and shape parameters. ```rust pub fn render_fox_avatar_for_identity( spec: AvatarSpec, identity: &AvatarIdentity, background: AvatarBackground, ) -> RgbaImage { assert!(spec.width >= 64, "width must be at least 64 pixels"); assert!(spec.height >= 64, "height must be at least 64 pixels"); let width = spec.width as i32; let height = spec.height as i32; let center_x = width / 2; let center_y = (height as f32 * 0.56) as i32; let mut image = ImageBuffer::from_pixel(spec.width, spec.height, Color::rgb(255, 255, 255).into()); let bg = hsl_to_color(22.0 + identity.unit_f32(0) * 26.0, 0.26, 0.92); let orange = hsl_to_color(18.0 + identity.unit_f32(1) * 20.0, 0.76, 0.58); let deep_orange = hsl_to_color(16.0 + identity.unit_f32(2) * 12.0, 0.72, 0.42); let cream = hsl_to_color(40.0 + identity.unit_f32(3) * 10.0, 0.32, 0.93); let eye = Color::rgb(34, 28, 24); let nose = Color::rgb(55, 40, 34); image .pixels_mut() .for_each(|pixel| *pixel = background_fill(background, bg).into()); let head_rx = (width as f32 * (0.25 + identity.unit_f32(4) * 0.08)) as i32; let head_ry = (height as f32 * (0.22 + identity.unit_f32(5) * 0.08)) as i32; let ear_h = (height as f32 * (0.16 + identity.unit_f32(6) * 0.09)) as i32; let ear_w = (width as f32 * (0.12 + identity.unit_f32(7) * 0.05)) as i32; draw_background_accent( &mut image, center_x, center_y, head_rx, head_ry, deep_orange, 0.35, background, ); draw_ear( &mut image, EarSpec::left(center_x, center_y, head_rx, head_ry, ear_w, ear_h, -0.2), orange, cream, deep_orange, ); draw_ear( &mut image, EarSpec::right(center_x, center_y, head_rx, head_ry, ear_w, ear_h, 0.2), orange, cream, deep_orange, ); draw_filled_ellipse_mut( &mut image, (center_x, center_y), head_rx, head_ry, orange.into(), ); draw_filled_ellipse_mut( &mut image, (center_x, center_y + head_ry / 4), head_rx / 2, head_ry / 3, cream.into(), ); draw_polygon_mut( &mut image, &[ ``` -------------------------------- ### Into and From Traits Source: https://docs.rs/hashavatar/0.3.0/hashavatar/enum.AvatarKind.html The `Into` and `From` traits provide a standard way to convert between types. `Into` is automatically implemented for `T` if `From` is implemented for `U`. ```APIDOC ## Into for T ### Description Calls `U::from(self)`. This conversion is determined by the implementation of `From for U`. ### Method `into()` ### Endpoint N/A (Trait method) ### Parameters None ### Request Example N/A ### Response #### Success Response Returns an instance of type `U`. #### Response Example N/A ## From for U ### Description Provides a way to convert type `T` into type `U`. ### Method `from(value: T)` ### Endpoint N/A (Trait method) ### Parameters - **value** (T) - The value to convert. ### Request Example N/A ### Response #### Success Response Returns an instance of type `U`. #### Response Example N/A ``` -------------------------------- ### Dog Avatar Rendering Source: https://docs.rs/hashavatar/0.3.0/src/hashavatar/lib.rs.html Structs and methods for rendering dog avatars based on identity and background. ```APIDOC ## Dog Avatar Rendering ### Description Provides functionality to create and render dog avatars. These avatars are based on a hashed identity and can have a specified background. ### Structs - **`HashedDogAvatar`**: Represents a dog avatar renderer driven by a SHA-512 identity and a background. - **`new`**: Creates a `HashedDogAvatar` with a default namespace, input identity, and background. - **`new_with_namespace`**: Creates a `HashedDogAvatar` with a specified namespace, input identity, and background. ### `AvatarRenderer` Implementation - The `HashedDogAvatar` struct implements the `AvatarRenderer` trait, allowing its `render` method to be called with `AvatarSpec` to produce an `RgbaImage`. - **`render`**: Renders the dog avatar using the identity, background, and specifications provided. ``` -------------------------------- ### Function signature for render_wizard_avatar_for_identity Source: https://docs.rs/hashavatar/0.3.0/hashavatar/fn.render_wizard_avatar_for_identity.html Defines the input parameters and return type for generating a wizard avatar. ```rust pub fn render_wizard_avatar_for_identity( spec: AvatarSpec, identity: &AvatarIdentity, background: AvatarBackground, ) -> RgbaImage ``` -------------------------------- ### UintsFrom Source: https://docs.rs/hashavatar/0.3.0/hashavatar/struct.AvatarOptions.html Casts a collection of colors into a collection of unsigned integers. ```APIDOC ## impl UintsFrom for U where C: IntoUints, ### Description Casts a collection of colors into a collection of unsigned integers. ### Method `uints_from(colors: C) -> U` Cast a collection of colors into a collection of unsigned integers. ``` -------------------------------- ### Clone to Uninitialized Memory (Nightly) Source: https://docs.rs/hashavatar/0.3.0/hashavatar/enum.AvatarBackground.html Performs copy-assignment from `self` to uninitialized memory pointed to by `dest`. This is an experimental nightly-only API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ```