pub enum AocOption {
Str(String),
Int(i64),
None,
}Expand description
Represents different types of option values that can be returned from your Advent of Code solutions. This enum provides a type-safe way to handle different value types that might be encountered as results.
§Variants
Str(String)- Contains a String value for text-based resultsInt(i64)- Contains a 64-bit signed integer value for numeric resultsNone- Represents the absence of a value or an unset option
§Automatic Conversions
This type implements From for multiple common types to make working with Advent of Code inputs easier:
Stringand&str->AocOption::Str- Small numeric types (
i8,i16,i32,i64,u8,u16,u32,isize,usize) ->AocOption::Int Option<T>where T implementsInto<AocOption>
For larger numeric types, TryFrom is implemented to handle potential conversion failures:
u64,i128,u128->Result<AocOption::Int, TryFromIntError>
§Example
let string_opt: AocOption = "puzzle input".to_string().into(); // Creates AocOption::Str
let num_opt: AocOption = 42_i32.into(); // Creates AocOption::Int
let some_opt: AocOption = Some(42_i32).into(); // Creates AocOption::Int
let none_opt: AocOption = None::<String>.into(); // Creates AocOption::None
// Using TryFrom for larger numbers
let big_num = u64::MAX;
let result = AocOption::try_from(big_num); // Returns ResultVariants§
Str(String)
Contains a String value for text-based results
Int(i64)
Contains a 128-bit signed integer value for numeric results
None
Represents the absence of a value or an unset option
Trait Implementations§
impl Eq for AocOption
impl StructuralPartialEq for AocOption
Auto Trait Implementations§
impl Freeze for AocOption
impl RefUnwindSafe for AocOption
impl Send for AocOption
impl Sync for AocOption
impl Unpin for AocOption
impl UnwindSafe for AocOption
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
Mutably borrows from an owned value. Read more