pub trait Shape: Send + Sync {
// Required method
fn path(&self) -> Result<Path2D, ValidationError>;
// Provided methods
fn bounding_box(&self) -> Result<Rect, ValidationError> { ... }
fn as_rect(&self) -> Option<Rect> { ... }
fn fill(self, paint: impl Into<Paint>) -> Styled<Self>
where Self: Sized { ... }
fn stroke(self, width: f64, paint: impl Into<Paint>) -> Styled<Self>
where Self: Sized { ... }
}Expand description
Logical geometry independent of paint and node placement.
Custom geometry must keep path and bounds consistent and deterministic.
Both queries report invalid geometry, such as a raw rectangle with nonfinite
edges, as a ValidationError instead of panicking.
Required Methods§
Sourcefn path(&self) -> Result<Path2D, ValidationError>
fn path(&self) -> Result<Path2D, ValidationError>
Returns a checked path snapshot without f32 narrowing.
Provided Methods§
Sourcefn bounding_box(&self) -> Result<Rect, ValidationError>
fn bounding_box(&self) -> Result<Rect, ValidationError>
Geometric bounds; defaults to the path’s cached curve bounds.
Sourcefn as_rect(&self) -> Option<Rect>
fn as_rect(&self) -> Option<Rect>
Exact rectangle equivalent, when available, for a rule-independent fast path.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".