19 yo student *and* a full-time developer.
Building with Rails currently, exploring new frontiers.
I enjoy functional programming, Linux, FOSS, refactoring and mentoring :)
I'm currently doing Rust, and I have a little trouble answering this question.
A couple points:
Rust does not have anything like dig built-in.
It wouldn't make sense, as there is no nil/null/whatever in Rust - if it's a String, it's there, no strings attached (pun intended).
To represent a value that might not be there, there is a concept of an Option enum, which can be either Some(value) or None (the concept is not new - Haskell has Maybe, and languages like Swift or Kotlin have nullable types)
A macro can probably do something like that for nested Options.
EDIT: I completely forgot about a cool language feature in Rust - ? operator.
Synopsis:
Result<T, E> is very similar to Option<T>, but it instead can be either Ok(T) (all good, T is the value) or Err(E) (something went wrong, E is the error type - String for a message, etc.)
result? basically means .if it's Ok, get the inner value and continue execution. If it's an Err, return it".
I'm currently doing Rust, and I have a little trouble answering this question.
A couple points:
dig
built-in.nil
/null
/whatever in Rust - if it's aString
, it's there, no strings attached (pun intended).Option
enum, which can be eitherSome(value)
orNone
(the concept is not new - Haskell hasMaybe
, and languages like Swift or Kotlin have nullable types)Options
.I came up with this:
Looks a bit funky, but does the job:
EDIT: I completely forgot about a cool language feature in Rust -
?
operator.Synopsis:
Result<T, E>
is very similar toOption<T>
, but it instead can be eitherOk(T)
(all good,T
is the value) orErr(E)
(something went wrong,E
is the error type -String
for a message, etc.)result?
basically means .if it's Ok, get the inner value and continue execution. If it's an Err,return
it".It allows for code like this: