Skip to main content

WithCs

Struct WithCs 

Source
#[repr(transparent)]
pub struct WithCs<T, Cs: CoordinateSystem> { pub inner: T, /* private fields */ }
Expand description

Re-tag any Point with a different coordinate system, without changing its storage layout.

Zero-cost: #[repr(transparent)] plus pure forwarding impls means &WithCs<T, Cs> is layout-compatible with &T and monomorphises to identical code. Only the Cs associated type of the Point impl changes — Scalar, DIM, get, and set all forward to the inner point.

See proposal §3.7 for the design rationale (orthogonality of shape vs. coordinate system, and the silent-Cartesian risk mitigation that lives in T31).

§Example

use geometry_adapt::{Adapt, WithCs};
use geometry_cs::{Degree, Geographic};
use geometry_trait::Point;

// An [f64; 2] adapted as a Cartesian point, then re-tagged as
// a geographic lat/lon pair in degrees.
let p: WithCs<Adapt<[f64; 2]>, Geographic<Degree>> =
    WithCs::new(Adapt([4.9, 52.4]));
assert_eq!(p.get::<0>(), 4.9);
assert_eq!(p.get::<1>(), 52.4);

Fields§

§inner: T

The wrapped inner point. Public so call sites can read or mutate the foreign storage directly when convenient.

Implementations§

Source§

impl<T, Cs: CoordinateSystem> WithCs<T, Cs>

Source

pub const fn new(inner: T) -> Self

Wrap an inner point and tag it with coordinate system Cs.

Source

pub fn into_inner(self) -> T

Unwrap, returning the inner point.

Trait Implementations§

Source§

impl<T: Clone, Cs: Clone + CoordinateSystem> Clone for WithCs<T, Cs>

Source§

fn clone(&self) -> WithCs<T, Cs>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy, Cs: Copy + CoordinateSystem> Copy for WithCs<T, Cs>

Source§

impl<T: Debug, Cs: Debug + CoordinateSystem> Debug for WithCs<T, Cs>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default, Cs: Default + CoordinateSystem> Default for WithCs<T, Cs>

Source§

fn default() -> WithCs<T, Cs>

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

impl<T: Eq, Cs: Eq + CoordinateSystem> Eq for WithCs<T, Cs>

Source§

impl<P: Point, Cs: CoordinateSystem> Geometry for WithCs<P, Cs>

Source§

type Kind = PointTag

One of the *Tag types from geometry_tag. Read more
Source§

type Point = WithCs<P, Cs>

The point type this geometry is built from. For a value modelling Point, this is Self. Read more
Source§

impl<T: Hash, Cs: Hash + CoordinateSystem> Hash for WithCs<T, Cs>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq, Cs: PartialEq + CoordinateSystem> PartialEq for WithCs<T, Cs>

Source§

fn eq(&self, other: &WithCs<T, Cs>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<P: Point, Cs: CoordinateSystem> Point for WithCs<P, Cs>

Source§

const DIM: usize = P::DIM

The number of dimensions. Read more
Source§

type Scalar = <P as Point>::Scalar

The scalar coordinate type. Read more
Source§

type Cs = Cs

The coordinate system this point lives in. Read more
Source§

fn get<const D: usize>(&self) -> P::Scalar

Read coordinate D. Read more
Source§

impl<P: PointMut, Cs: CoordinateSystem> PointMut for WithCs<P, Cs>

Source§

fn set<const D: usize>(&mut self, value: P::Scalar)

Write coordinate D. Read more
Source§

impl<T: PartialEq, Cs: PartialEq + CoordinateSystem> StructuralPartialEq for WithCs<T, Cs>

Auto Trait Implementations§

§

impl<T, Cs> Freeze for WithCs<T, Cs>
where T: Freeze,

§

impl<T, Cs> RefUnwindSafe for WithCs<T, Cs>

§

impl<T, Cs> Send for WithCs<T, Cs>
where T: Send, Cs: Send,

§

impl<T, Cs> Sync for WithCs<T, Cs>
where T: Sync, Cs: Sync,

§

impl<T, Cs> Unpin for WithCs<T, Cs>
where T: Unpin, Cs: Unpin,

§

impl<T, Cs> UnsafeUnpin for WithCs<T, Cs>
where T: UnsafeUnpin,

§

impl<T, Cs> UnwindSafe for WithCs<T, Cs>
where T: UnwindSafe, Cs: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> SameAs<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.