pub enum Answer {
String(String),
Int(i128),
}Expand description
Represents an Advent of Code integer or string puzzle answer. Answers may or may not be valid solutions.
use advent_of_code_data::Answer;
let string_answer = Answer::String("hello world".to_string());
let int_answer = Answer::Int(42);§Automatic Conversions
Answer implements From for common string and integer types:
String, &str->Answer::String`- Numeric types (
i8,i16,i32,i64,isize,usize, etc) ->Answer::Int
use advent_of_code_data::Answer;
let string_answer: Answer = "hello world".into();
assert_eq!(string_answer, Answer::String("hello world".to_string()));
let int_answer: Answer = 42.into();
assert_eq!(int_answer, Answer::Int(42));§FromStr (string parsing)
Answer supports string parsing for both integer and string values.
use advent_of_code_data::Answer;
let answer: Answer = "testing 123".parse::<Answer>().unwrap();
assert_eq!(answer, Answer::String("testing 123".to_string()));
let answer: Answer = "-5713".parse::<Answer>().unwrap();
assert_eq!(answer, Answer::Int(-5713));Variants§
Implementations§
Trait Implementations§
impl StructuralPartialEq for Answer
Auto Trait Implementations§
impl Freeze for Answer
impl RefUnwindSafe for Answer
impl Send for Answer
impl Sync for Answer
impl Unpin for Answer
impl UnwindSafe for Answer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.