]> git.lizzy.rs Git - rust.git/commitdiff
Generalized implementation of FromBase64
authorSteven Fackler <sfackler@gmail.com>
Wed, 29 May 2013 01:41:05 +0000 (18:41 -0700)
committerSteven Fackler <sfackler@gmail.com>
Wed, 29 May 2013 01:41:05 +0000 (18:41 -0700)
Previously, FromBase64 was only implemented on ~[u8] and ~str when
any pointer would do. The implementations of FromBase64 are now
consistent with the implementations of ToBase64.

src/libextra/base64.rs

index e06bf2844828489e3193a5fefa1e951776efde51..7829eb50a68dd7c089211055a36e60849d4c4eae 100644 (file)
@@ -113,7 +113,7 @@ pub trait FromBase64 {
     fn from_base64(&self) -> ~[u8];
 }
 
-impl FromBase64 for ~[u8] {
+impl<'self> FromBase64 for &'self [u8] {
     /**
      * Convert base64 `u8` vector into u8 byte values.
      * Every 4 encoded characters is converted into 3 octets, modulo padding.
@@ -188,7 +188,7 @@ fn from_base64(&self) -> ~[u8] {
     }
 }
 
-impl FromBase64 for ~str {
+impl<'self> FromBase64 for &'self str {
     /**
      * Convert any base64 encoded string (literal, `@`, `&`, or `~`)
      * to the byte values it encodes.
@@ -227,23 +227,23 @@ mod tests {
 
     #[test]
     fn test_to_base64() {
-        assert_eq!((~"").to_base64(), ~"");
-        assert!((~"f").to_base64()      == ~"Zg==");
-        assert_eq!((~"fo").to_base64(), ~"Zm8=");
-        assert_eq!((~"foo").to_base64(), ~"Zm9v");
-        assert!((~"foob").to_base64()   == ~"Zm9vYg==");
-        assert_eq!((~"fooba").to_base64(), ~"Zm9vYmE=");
-        assert_eq!((~"foobar").to_base64(), ~"Zm9vYmFy");
+        assert_eq!("".to_base64(), ~"");
+        assert_eq!("f".to_base64(), ~"Zg==");
+        assert_eq!("fo".to_base64(), ~"Zm8=");
+        assert_eq!("foo".to_base64(), ~"Zm9v");
+        assert_eq!("foob".to_base64(), ~"Zm9vYg==");
+        assert_eq!("fooba".to_base64(), ~"Zm9vYmE=");
+        assert_eq!("foobar".to_base64(), ~"Zm9vYmFy");
     }
 
     #[test]
     fn test_from_base64() {
-        assert_eq!((~"").from_base64(), str::to_bytes(""));
-        assert!((~"Zg==").from_base64() == str::to_bytes("f"));
-        assert_eq!((~"Zm8=").from_base64(), str::to_bytes("fo"));
-        assert_eq!((~"Zm9v").from_base64(), str::to_bytes("foo"));
-        assert!((~"Zm9vYg==").from_base64() == str::to_bytes("foob"));
-        assert_eq!((~"Zm9vYmE=").from_base64(), str::to_bytes("fooba"))
-        assert_eq!((~"Zm9vYmFy").from_base64(), str::to_bytes("foobar"));
+        assert_eq!("".from_base64(), str::to_bytes(""));
+        assert_eq!("Zg==".from_base64(), str::to_bytes("f"));
+        assert_eq!("Zm8=".from_base64(), str::to_bytes("fo"));
+        assert_eq!("Zm9v".from_base64(), str::to_bytes("foo"));
+        assert_eq!("Zm9vYg==".from_base64(), str::to_bytes("foob"));
+        assert_eq!("Zm9vYmE=".from_base64(), str::to_bytes("fooba"))
+        assert_eq!("Zm9vYmFy".from_base64(), str::to_bytes("foobar"));
     }
 }