mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-09 14:48:00 +00:00
Move DeriveBuiltin to derive_key
This commit is contained in:
parent
6f06a59cdf
commit
05d8bca0fb
4 changed files with 99 additions and 92 deletions
|
@ -57,11 +57,23 @@ pub enum Derived {
|
|||
Key(DeriveKey),
|
||||
}
|
||||
|
||||
/// The builtin ability member to derive.
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum DeriveBuiltin {
|
||||
ToEncoder,
|
||||
}
|
||||
|
||||
impl Derived {
|
||||
pub fn encoding(subs: &Subs, var: Variable) -> Result<Self, DeriveError> {
|
||||
match encoding::FlatEncodable::from_var(subs, var)? {
|
||||
FlatEncodable::Immediate(imm) => Ok(Derived::Immediate(imm)),
|
||||
FlatEncodable::Key(repr) => Ok(Derived::Key(DeriveKey::ToEncoder(repr))),
|
||||
pub fn builtin(
|
||||
builtin: DeriveBuiltin,
|
||||
subs: &Subs,
|
||||
var: Variable,
|
||||
) -> Result<Self, DeriveError> {
|
||||
match builtin {
|
||||
DeriveBuiltin::ToEncoder => match encoding::FlatEncodable::from_var(subs, var)? {
|
||||
FlatEncodable::Immediate(imm) => Ok(Derived::Immediate(imm)),
|
||||
FlatEncodable::Key(repr) => Ok(Derived::Key(DeriveKey::ToEncoder(repr))),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue