Skip to content

Commit 3cddf5c

Browse files
committed
Replace instances of Result<..., rustler::Error> with NifResult<..>
This reduces the amount of typing slightly with no functional change
1 parent c58d57c commit 3cddf5c

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

arm/src/encryption.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl SecretKey {
3434
}
3535

3636
#[cfg(feature = "nif")]
37-
fn do_encode<'a>(secret_key: &SecretKey, env: Env<'a>) -> Result<Term<'a>, Error> {
37+
fn do_encode<'a>(secret_key: &SecretKey, env: Env<'a>) -> NifResult<Term<'a>> {
3838
let bytes = bincode::serialize(&secret_key.0).unwrap();
3939

4040
let mut erl_bin = OwnedBinary::new(bytes.len()).ok_or(Error::BadArg)?;

arm/src/rustler_util.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ atoms! {
8787
}
8888

8989
pub trait RustlerEncoder {
90-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error>;
90+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>>;
9191
}
9292

9393
pub trait RustlerDecoder<'a>: Sized + 'a {
9494
fn rustler_decode(term: Term<'a>) -> NifResult<Self>;
9595
}
9696

9797
impl RustlerEncoder for Vec<u8> {
98-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
98+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
9999
let mut erl_bin = OwnedBinary::new(self.len())
100100
.ok_or("could not create OwnedBinary")
101101
.expect("could not allocate binary");
@@ -112,7 +112,7 @@ impl<'a> RustlerDecoder<'a> for Vec<u8> {
112112
}
113113

114114
impl RustlerEncoder for Vec<u32> {
115-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
115+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
116116
let mut erl_bin: OwnedBinary = OwnedBinary::new(self.len() * 4)
117117
.ok_or("could not create OwnedBinary")
118118
.expect("could not allocate binary");
@@ -132,7 +132,7 @@ impl<'a> RustlerDecoder<'a> for Vec<u32> {
132132
}
133133

134134
impl RustlerEncoder for AffinePoint {
135-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
135+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
136136
bincode::serialize(self)
137137
.expect("failed to encode AffinePoint")
138138
.rustler_encode(env)
@@ -148,7 +148,7 @@ impl<'a> RustlerDecoder<'a> for AffinePoint {
148148
}
149149

150150
impl RustlerEncoder for Signature {
151-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
151+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
152152
bincode::serialize(self)
153153
.expect("failed to encode Signature")
154154
.rustler_encode(env)
@@ -164,7 +164,7 @@ impl<'a> RustlerDecoder<'a> for Signature {
164164
}
165165

166166
impl RustlerEncoder for RecoveryId {
167-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
167+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
168168
let byte: u8 = self.to_byte();
169169
Ok(byte.encode(env))
170170
}
@@ -178,7 +178,7 @@ impl<'a> RustlerDecoder<'a> for RecoveryId {
178178
}
179179

180180
impl RustlerEncoder for SigningKey {
181-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
181+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
182182
let bytes = self.to_bytes();
183183
let bytez = bytes.to_vec();
184184
RustlerEncoder::rustler_encode(&bytez, env)
@@ -196,7 +196,7 @@ impl<'a> RustlerDecoder<'a> for SigningKey {
196196
// ComplianceUnit
197197

198198
impl RustlerEncoder for ComplianceUnit {
199-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
199+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
200200
let map = map_new(env)
201201
.map_put(at_struct().encode(env), at_compliance_unit().encode(env))?
202202
.map_put(at_proof().encode(env), self.proof.rustler_encode(env)?)?
@@ -236,7 +236,7 @@ impl<'a> Decoder<'a> for ComplianceUnit {
236236
// ExpirableBlob
237237

238238
impl RustlerEncoder for ExpirableBlob {
239-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
239+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
240240
let map = map_new(env)
241241
.map_put(at_struct().encode(env), at_expirable_blob().encode(env))?
242242
.map_put(at_blob().encode(env), self.blob.rustler_encode(env)?)?
@@ -279,7 +279,7 @@ impl<'a> Decoder<'a> for ExpirableBlob {
279279
// AppData
280280

281281
impl RustlerEncoder for AppData {
282-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
282+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
283283
let map = map_new(env)
284284
.map_put(at_struct().encode(env), at_app_data().encode(env))?
285285
.map_put(
@@ -340,7 +340,7 @@ impl<'a> Decoder<'a> for AppData {
340340
// LogicVerifierInputs
341341

342342
impl RustlerEncoder for LogicVerifierInputs {
343-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
343+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
344344
let map = map_new(env)
345345
.map_put(
346346
at_struct().encode(env),
@@ -395,7 +395,7 @@ impl<'a> Decoder<'a> for LogicVerifierInputs {
395395
// Action
396396

397397
impl RustlerEncoder for Action {
398-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
398+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
399399
let map = map_new(env)
400400
.map_put(at_struct().encode(env), at_action().encode(env))?
401401
.map_put(
@@ -444,7 +444,7 @@ impl<'a> Decoder<'a> for Action {
444444
// MerkleTree
445445

446446
impl RustlerEncoder for MerkleTree {
447-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
447+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
448448
// encode the leaves separately.
449449
// each leaf is a vec<u32> and we have to encode those as a binary individually.
450450
let encoded_vec: Term = self
@@ -497,7 +497,7 @@ impl<'a> Decoder<'a> for MerkleTree {
497497
// MerklePath
498498

499499
impl RustlerEncoder for MerklePath {
500-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
500+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
501501
let encoded_vec: Vec<Term> = self
502502
.0
503503
.iter()
@@ -553,7 +553,7 @@ impl<'a> Decoder<'a> for MerklePath {
553553
// ComplianceInstance
554554

555555
impl RustlerEncoder for ComplianceInstance {
556-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
556+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
557557
let map = map_new(env)
558558
.map_put(
559559
at_struct().encode(env),
@@ -643,7 +643,7 @@ impl<'a> Decoder<'a> for ComplianceInstance {
643643
// ComplianceWitness
644644

645645
impl RustlerEncoder for ComplianceWitness {
646-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
646+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
647647
let map = map_new(env)
648648
.map_put(at_struct().encode(env), at_compliance_witness().encode(env))?
649649
.map_put(
@@ -717,7 +717,7 @@ impl<'a> Decoder<'a> for ComplianceWitness {
717717
// NullifierKeyCommitment
718718

719719
impl RustlerEncoder for NullifierKeyCommitment {
720-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
720+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
721721
let inner_bytes = self.inner().to_vec();
722722
inner_bytes.rustler_encode(env)
723723
}
@@ -747,7 +747,7 @@ impl<'a> Decoder<'a> for NullifierKeyCommitment {
747747
// NullifierKey
748748

749749
impl RustlerEncoder for NullifierKey {
750-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
750+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
751751
let inner_bytes = self.inner().to_vec();
752752
inner_bytes.rustler_encode(env)
753753
}
@@ -777,7 +777,7 @@ impl<'a> Decoder<'a> for NullifierKey {
777777
// Resource
778778

779779
impl RustlerEncoder for Resource {
780-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
780+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
781781
let map = map_new(env)
782782
.map_put(at_struct().encode(env), at_resource().encode(env))?
783783
.map_put(
@@ -865,7 +865,7 @@ impl<'a> Decoder<'a> for Resource {
865865
// DeltaProof
866866

867867
impl RustlerEncoder for DeltaProof {
868-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
868+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
869869
let map = map_new(env)
870870
.map_put(at_struct().encode(env), at_delta_proof().encode(env))?
871871
.map_put(
@@ -907,7 +907,7 @@ impl<'a> Decoder<'a> for DeltaProof {
907907
// DeltaWitness
908908

909909
impl RustlerEncoder for DeltaWitness {
910-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
910+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
911911
let map = map_new(env)
912912
.map_put(at_struct().encode(env), at_delta_witness().encode(env))?
913913
.map_put(
@@ -945,7 +945,7 @@ impl<'a> Decoder<'a> for DeltaWitness {
945945
// LogicVerifier
946946

947947
impl RustlerEncoder for LogicVerifier {
948-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
948+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
949949
let map = map_new(env)
950950
.map_put(at_struct().encode(env), at_logic_verifier().encode(env))?
951951
.map_put(at_proof().encode(env), self.proof.rustler_encode(env)?)?
@@ -998,7 +998,7 @@ impl<'a> Decoder<'a> for LogicVerifier {
998998
// Transaction
999999

10001000
impl RustlerEncoder for Transaction {
1001-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
1001+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
10021002
let map = map_new(env)
10031003
.map_put(at_struct().encode(env), at_transaction().encode(env))?
10041004
.map_put(at_actions().encode(env), self.actions.encode(env))?
@@ -1057,7 +1057,7 @@ impl<'a> Decoder<'a> for Transaction {
10571057
// Delta
10581058

10591059
impl RustlerEncoder for Delta {
1060-
fn rustler_encode<'a>(&self, env: Env<'a>) -> Result<Term<'a>, Error> {
1060+
fn rustler_encode<'a>(&self, env: Env<'a>) -> NifResult<Term<'a>> {
10611061
Ok(self.encode(env))
10621062
}
10631063
}

0 commit comments

Comments
 (0)