Skip to content

Commit 2de65b8

Browse files
committed
Fix sticker implementation.
1 parent 7bf375f commit 2de65b8

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,10 @@ impl<S: Read + Write> Client<S> {
598598
// Sticker methods {{{
599599
/// Show sticker value for a given object, identified by type and uri
600600
pub fn sticker(&mut self, typ: &str, uri: &str, name: &str) -> Result<String> {
601-
self.run_command("sticker set", (typ, uri, name))
602-
.and_then(|_| self.read_field("sticker"))
601+
self.run_command("sticker get", (typ, uri, name))
602+
// TODO: This should parse to a `Sticker` type.
603+
.and_then(|_| self.read_field::<String>("sticker"))
604+
.and_then(|s| s.splitn(2, '=').nth(1).map(str::to_owned).ok_or_else(|| Error::Proto(ProtoError::BadSticker)))
603605
}
604606

605607
/// Set sticker value for a given object, identified by type and uri

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ pub enum ProtoError {
370370
BadBanner,
371371
/// expected some field, but it was missing
372372
NoField(&'static str),
373+
/// expected sticker value, but didn't find it
374+
BadSticker,
373375
}
374376

375377
impl fmt::Display for ProtoError {
@@ -385,6 +387,7 @@ impl StdError for ProtoError {
385387
ProtoError::NotPair => "pair expected",
386388
ProtoError::BadBanner => "banner error",
387389
ProtoError::NoField(_) => "missing field",
390+
ProtoError::BadSticker => "sticker error",
388391
}
389392
}
390393
}

src/proto.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ pub trait Proto {
162162
}
163163
}
164164

165-
fn read_field<T, E>(&mut self, field: &'static str) -> Result<T>
166-
where T: FromStr<Err = E>,
167-
ParseError: From<E>
165+
fn read_field<T: FromStr>(&mut self, field: &'static str) -> Result<T>
166+
where ParseError: From<T::Err>
168167
{
169168
let (a, b) = self.read_pair()?;
170169
self.expect_ok()?;

0 commit comments

Comments
 (0)