Skip to content

Commit c06263d

Browse files
committed
Return Result<Self, Self::Err> in FromStr impls
If we return `Self, Self::Err` then the implementations of `FromStr` are easier to maintain.
1 parent 29e1a0c commit c06263d

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/ecdh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl SharedSecret {
7979

8080
impl str::FromStr for SharedSecret {
8181
type Err = Error;
82-
fn from_str(s: &str) -> Result<SharedSecret, Error> {
82+
fn from_str(s: &str) -> Result<Self, Self::Err> {
8383
let mut res = [0u8; SHARED_SECRET_SIZE];
8484
match crate::from_hex(s, &mut res) {
8585
Ok(SHARED_SECRET_SIZE) => Ok(SharedSecret::from_bytes(res)),

src/ecdsa/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl fmt::Display for Signature {
3737

3838
impl str::FromStr for Signature {
3939
type Err = Error;
40-
fn from_str(s: &str) -> Result<Signature, Error> {
40+
fn from_str(s: &str) -> Result<Self, Self::Err> {
4141
let mut res = [0u8; 72];
4242
match from_hex(s, &mut res) {
4343
Ok(x) => Signature::from_der(&res[0..x]),

src/key.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl ffi::CPtr for SecretKey {
106106

107107
impl str::FromStr for SecretKey {
108108
type Err = Error;
109-
fn from_str(s: &str) -> Result<SecretKey, Error> {
109+
fn from_str(s: &str) -> Result<Self, Self::Err> {
110110
let mut res = [0u8; constants::SECRET_KEY_SIZE];
111111
match from_hex(s, &mut res) {
112112
Ok(constants::SECRET_KEY_SIZE) => SecretKey::from_slice(&res),
@@ -159,7 +159,7 @@ impl fmt::Display for PublicKey {
159159

160160
impl str::FromStr for PublicKey {
161161
type Err = Error;
162-
fn from_str(s: &str) -> Result<PublicKey, Error> {
162+
fn from_str(s: &str) -> Result<Self, Self::Err> {
163163
let mut res = [0u8; constants::UNCOMPRESSED_PUBLIC_KEY_SIZE];
164164
match from_hex(s, &mut res) {
165165
Ok(constants::PUBLIC_KEY_SIZE) =>
@@ -1111,7 +1111,7 @@ impl fmt::Display for XOnlyPublicKey {
11111111

11121112
impl str::FromStr for XOnlyPublicKey {
11131113
type Err = Error;
1114-
fn from_str(s: &str) -> Result<XOnlyPublicKey, Error> {
1114+
fn from_str(s: &str) -> Result<Self, Self::Err> {
11151115
let mut res = [0u8; constants::SCHNORR_PUBLIC_KEY_SIZE];
11161116
match from_hex(s, &mut res) {
11171117
Ok(constants::SCHNORR_PUBLIC_KEY_SIZE) =>

src/schnorr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl fmt::Display for Signature {
6464

6565
impl str::FromStr for Signature {
6666
type Err = Error;
67-
fn from_str(s: &str) -> Result<Signature, Error> {
67+
fn from_str(s: &str) -> Result<Self, Self::Err> {
6868
let mut res = [0u8; constants::SCHNORR_SIGNATURE_SIZE];
6969
match from_hex(s, &mut res) {
7070
Ok(constants::SCHNORR_SIGNATURE_SIZE) =>

0 commit comments

Comments
 (0)