File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # 5.1.0
2+ - Add implementations of ` AsRef ` and ` AsMut `
3+ - Enable all features on ` docs.rs `
4+ - Remove now default ` intra_rustdoc_links ` feature flag
5+
16# 5.0.1
27- Update registry to latest version: Release 98.
38- Update country specific generation code. Inconsistencies are now resolved manually when generating the country specific code. Incorrect examples are now fixed before testing where they were previously ignored.
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ authors = ["Thomas den Hollander <denhollander.thomas@gmail.com>"]
66description = " A small crate to verify IBAN account numbers."
77repository = " https://github.com/ThomasdenH/iban_check"
88license = " MIT OR Apache-2.0"
9- readme = " ../ README.md"
9+ readme = " README.md"
1010keywords = [" iban" , " iban-validator" ]
1111categories = [" parsing" ]
1212edition = " 2021"
@@ -21,8 +21,10 @@ path = "src/lib.rs"
2121
2222[features ]
2323default = []
24- # Builds rustdoc links, but requires nightly
25- intra_rustdoc_links = []
24+
25+ # Enables all features when building documentation
26+ [package .metadata .docs .rs ]
27+ features = [" serde" ]
2628
2729[dependencies .serde ]
2830version = " 1"
Original file line number Diff line number Diff line change @@ -205,6 +205,18 @@ impl fmt::Display for ParseBaseIbanError {
205205
206206impl Error for ParseBaseIbanError { }
207207
208+ impl AsRef < ParseBaseIbanError > for ParseBaseIbanError {
209+ fn as_ref ( & self ) -> & ParseBaseIbanError {
210+ self
211+ }
212+ }
213+
214+ impl AsMut < ParseBaseIbanError > for ParseBaseIbanError {
215+ fn as_mut ( & mut self ) -> & mut ParseBaseIbanError {
216+ self
217+ }
218+ }
219+
208220impl BaseIban {
209221 /// Compute the checksum for the address. The code that the string contains
210222 /// only valid characters: `'0'..='9'` and `'A'..='Z'`.
@@ -372,3 +384,15 @@ impl<'a> TryFrom<&'a str> for BaseIban {
372384 value. parse ( )
373385 }
374386}
387+
388+ impl AsRef < BaseIban > for BaseIban {
389+ fn as_ref ( & self ) -> & BaseIban {
390+ self
391+ }
392+ }
393+
394+ impl AsMut < BaseIban > for BaseIban {
395+ fn as_mut ( & mut self ) -> & mut BaseIban {
396+ self
397+ }
398+ }
Original file line number Diff line number Diff line change @@ -314,6 +314,18 @@ impl Error for ParseIbanError {
314314 }
315315}
316316
317+ impl AsRef < ParseIbanError > for ParseIbanError {
318+ fn as_ref ( & self ) -> & ParseIbanError {
319+ self
320+ }
321+ }
322+
323+ impl AsMut < ParseIbanError > for ParseIbanError {
324+ fn as_mut ( & mut self ) -> & mut ParseIbanError {
325+ self
326+ }
327+ }
328+
317329impl < ' a > TryFrom < & ' a str > for Iban {
318330 type Error = ParseIbanError ;
319331 /// Parse an IBAN without taking the BBAN into consideration.
@@ -365,6 +377,24 @@ impl str::FromStr for Iban {
365377 }
366378}
367379
380+ impl AsRef < Iban > for Iban {
381+ fn as_ref ( & self ) -> & Iban {
382+ self
383+ }
384+ }
385+
386+ impl AsMut < Iban > for Iban {
387+ fn as_mut ( & mut self ) -> & mut Iban {
388+ self
389+ }
390+ }
391+
392+ impl AsRef < BaseIban > for Iban {
393+ fn as_ref ( & self ) -> & BaseIban {
394+ & self . base_iban
395+ }
396+ }
397+
368398#[ cfg( feature = "serde" ) ]
369399impl Serialize for Iban {
370400 #[ inline]
Original file line number Diff line number Diff line change 1+ use core:: error:: Error ;
2+
3+ use iban:: { BaseIban , Iban } ;
4+
5+ /// [`Iban`] implements [`AsRef`] to [`BaseIban`]. Test it here and see if it
6+ /// displays the same.
7+ #[ test]
8+ fn test_as_ref ( ) -> Result < ( ) , Box < dyn Error > > {
9+ let iban: Iban = "KW81CBKU0000000000001234560101" . parse ( ) ?;
10+
11+ fn pretty_format ( base_iban : impl AsRef < BaseIban > ) -> String {
12+ let base_iban: & BaseIban = base_iban. as_ref ( ) ;
13+ base_iban. to_string ( )
14+ }
15+
16+ let s = pretty_format ( iban) ;
17+ assert_eq ! ( s. as_str( ) , "KW81 CBKU 0000 0000 0000 1234 5601 01" ) ;
18+ assert_eq ! ( iban. to_string( ) , s) ;
19+
20+ Ok ( ( ) )
21+ }
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ assert_impl_all!(
1818 TryFrom <& ' static str >,
1919 Send ,
2020 Sync ,
21- From <Iban >
21+ From <Iban >,
22+ AsRef <BaseIban >,
23+ AsMut <BaseIban >
2224) ;
2325assert_impl_all ! (
2426 Iban : Copy ,
@@ -33,7 +35,12 @@ assert_impl_all!(
3335 TryFrom <& ' static str >,
3436 Send ,
3537 Sync ,
36- Into <BaseIban >
38+ Into <BaseIban >,
39+ // We can convert between references. We cannot convert between mutable
40+ // references, since a changed BaseIban may not be a valid Iban anymore.
41+ AsRef <BaseIban >,
42+ AsRef <Iban >,
43+ AsMut <Iban >
3744) ;
3845assert_impl_all ! (
3946 ParseBaseIbanError : Copy ,
@@ -45,7 +52,9 @@ assert_impl_all!(
4552 Send ,
4653 Sync ,
4754 Display ,
48- Into <ParseIbanError >
55+ Into <ParseIbanError >,
56+ AsRef <ParseBaseIbanError >,
57+ AsMut <ParseBaseIbanError >
4958) ;
5059assert_impl_all ! (
5160 ParseIbanError : Copy ,
@@ -57,7 +66,9 @@ assert_impl_all!(
5766 Send ,
5867 Sync ,
5968 Display ,
60- From <ParseBaseIbanError >
69+ From <ParseBaseIbanError >,
70+ AsRef <ParseIbanError >,
71+ AsMut <ParseIbanError >
6172) ;
6273
6374assert_impl_all ! ( ParseBaseIbanError : core:: error:: Error ) ;
You can’t perform that action at this time.
0 commit comments