pub struct Rotation(/* private fields */);Expand description
Clockwise rotation in whole degrees, applied after auto-orientation.
Any integer is accepted and normalized into 0..360, so a negative angle turns
counter-clockwise and a value past a full turn wraps: -90 and 270 are the same
rotation, and so are 370 and 10.
Degrees are whole numbers on purpose. The value appears verbatim in the cache key and in the signed-URL canonical string, and a fractional angle would have to round-trip bit-identically through Rust’s and JavaScript’s float formatting for a signature to verify. Whole degrees sidestep that entirely, and no real caller asks for a fraction of one.
§Examples
use truss::Rotation;
use std::str::FromStr;
let rot = Rotation::from_str("270").unwrap();
assert_eq!(rot.as_degrees(), 270);
// Negative turns counter-clockwise, and wraps to the same rotation.
assert_eq!(Rotation::from_str("-90").unwrap(), rot);
// Angles past a full turn wrap too.
assert_eq!(Rotation::from_str("630").unwrap(), rot);
// Any whole angle is allowed, not just quarter turns.
assert_eq!(Rotation::from_str("45").unwrap().as_degrees(), 45);
assert!(Rotation::from_str("45.5").is_err());
assert!(Rotation::DEG_0.is_identity());
assert_eq!(Rotation::DEG_90.quarter_turns(), Some(1));
assert_eq!(Rotation::from_degrees(45).quarter_turns(), None);Implementations§
Source§impl Rotation
impl Rotation
Sourcepub const fn from_degrees(degrees: i32) -> Self
pub const fn from_degrees(degrees: i32) -> Self
Builds a rotation from any whole number of degrees, normalizing into 0..360.
Positive turns clockwise and negative turns counter-clockwise, which is the
convention --rotate has always used and the one image tools generally agree on.
Sourcepub const fn as_degrees(self) -> u16
pub const fn as_degrees(self) -> u16
Returns the normalized degree value used by the API, the CLI, and the cache key.
Sourcepub const fn is_identity(self) -> bool
pub const fn is_identity(self) -> bool
Returns true when the rotation leaves the image untouched.
Sourcepub const fn quarter_turns(self) -> Option<u8>
pub const fn quarter_turns(self) -> Option<u8>
Returns the number of clockwise quarter turns when the angle is a multiple of 90.
A quarter turn only permutes pixels, so the pipeline keeps that exact path instead
of resampling. Anything else returns None and goes through the general rotation.
Trait Implementations§
impl Copy for Rotation
impl Eq for Rotation
Source§impl Ord for Rotation
impl Ord for Rotation
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Rotation
impl PartialOrd for Rotation
impl StructuralPartialEq for Rotation
Auto Trait Implementations§
impl Freeze for Rotation
impl RefUnwindSafe for Rotation
impl Send for Rotation
impl Sync for Rotation
impl Unpin for Rotation
impl UnsafeUnpin for Rotation
impl UnwindSafe for Rotation
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> ⓘ
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> ⓘ
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 more