Skip to main content

Mode

Enum Mode 

Source
#[non_exhaustive]
pub enum Mode { Int8 = 0, Int16 = 1, Float32 = 2, Int16Complex = 3, Float32Complex = 4, Uint16 = 6, Float16 = 12, Packed4Bit = 101, }
Expand description

MRC data mode defining the on-disk representation of voxel values.

§Example

use mrc::Mode;

let mode = Mode::Float32;
assert_eq!(mode.byte_size(), 4);
assert!(mode.is_float());
assert!(!mode.is_integer());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Int8 = 0

Signed 8-bit integer (Mode 0).

§

Int16 = 1

Signed 16-bit integer (Mode 1).

§

Float32 = 2

32-bit floating point (Mode 2).

§

Int16Complex = 3

Complex number with 16-bit integer components (Mode 3)

§Byte Order

The layout is [real i16 (2 bytes), imag i16 (2 bytes)] which matches the de facto standard used by CCP4, IMOD, and other MRC implementations. This is not explicitly specified in MRC2014 but is universally adopted.

§

Float32Complex = 4

Complex number with 32-bit float components (Mode 4)

§Byte Order

The layout is [real f32 (4 bytes), imag f32 (4 bytes)] which matches the de facto standard used by CCP4, IMOD, and other MRC implementations. This is not explicitly specified in MRC2014 but is universally adopted.

§

Uint16 = 6

Unsigned 16-bit integer (Mode 6).

§

Float16 = 12

16-bit floating point (Mode 12).

§

Packed4Bit = 101

4-bit data packed two values per byte (Mode 101).

Each byte stores two 4-bit nibbles: low nibble = first pixel, high nibble = second pixel. Read via slices_u8 or convert::<f32>(); write via write_u4_block.

Implementations§

Source§

impl Mode

Source

pub const fn as_i32(self) -> i32

Return the MRC mode constant as an i32 value.

§Example
use mrc::Mode;

assert_eq!(Mode::Int8.as_i32(), 0);
assert_eq!(Mode::Float32.as_i32(), 2);
Source

pub fn from_i32(mode: i32) -> Option<Self>

Convert an MRC mode integer to a Mode enum value.

Returns None for unrecognized mode values.

§Example
use mrc::Mode;

assert_eq!(Mode::from_i32(2), Some(Mode::Float32));
assert_eq!(Mode::from_i32(99), None);
Source

pub fn byte_size(&self) -> usize

Number of bytes required to store one voxel in this mode.

For Packed4Bit this returns 1 (two voxels per byte); use byte_size_for_count for per-voxel sizing.

§Example
use mrc::Mode;

assert_eq!(Mode::Int16.byte_size(), 2);
assert_eq!(Mode::Float32Complex.byte_size(), 8);
Source

pub fn is_complex(&self) -> bool

Returns true if this mode stores complex numbers (real + imaginary components).

§Example
use mrc::Mode;

assert!(Mode::Int16Complex.is_complex());
assert!(!Mode::Float32.is_complex());
Source

pub fn is_integer(&self) -> bool

Returns true if this mode stores integer-valued data (including complex integers).

§Example
use mrc::Mode;

assert!(Mode::Uint16.is_integer());
assert!(!Mode::Float32.is_integer());
Source

pub fn is_float(&self) -> bool

Returns true if this mode stores floating-point data (including complex float).

§Example
use mrc::Mode;

assert!(Mode::Float16.is_float());
assert!(!Mode::Int8.is_float());
Source

pub fn byte_size_for_count(&self, n: usize) -> usize

Byte size for a given number of voxels.

For most modes this is n * byte_size(), but Packed4Bit stores two voxels per byte so the result is n.div_ceil(2).

§Example
use mrc::Mode;

assert_eq!(Mode::Int16.byte_size_for_count(3), 6);
assert_eq!(Mode::Packed4Bit.byte_size_for_count(3), 2);

Trait Implementations§

Source§

impl Clone for Mode

Source§

fn clone(&self) -> Mode

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 Copy for Mode

Source§

impl Debug for Mode

Source§

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

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

impl Eq for Mode

Source§

impl PartialEq for Mode

Source§

fn eq(&self, other: &Mode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Mode

Auto Trait Implementations§

§

impl Freeze for Mode

§

impl RefUnwindSafe for Mode

§

impl Send for Mode

§

impl Sync for Mode

§

impl Unpin for Mode

§

impl UnsafeUnpin for Mode

§

impl UnwindSafe for Mode

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more