History

[packetline #178] fix docs

Sebastian Thiel committed 5 years ago

Commit b3fd65d1 parent 23438fd2 files · +10 −10Browse files

Unified · Split

2 files
  1. git-packetline/src/line/mod.rs +9 −9
  2. git-packetline/src/read/mod.rs +1 −1
git-packetline/src/line/mod.rs+9−9
@@ -3,27 +3,27 @@ use bstr::BStr; · 2 unmodified lines
3use crate::{decode, BandRef, Channel, ErrorRef, PacketLineRef, TextRef, ERR_PREFIX};3use crate::{decode, BandRef, Channel, ErrorRef, PacketLineRef, TextRef, ERR_PREFIX};
4 4
5impl<'a> PacketLineRef<'a> {5impl<'a> PacketLineRef<'a> {
6 /// Return this instance as slice if it's [`Data`][PacketLine::Data].6 /// Return this instance as slice if it's [`Data`][PacketLineRef::Data].
7 pub fn as_slice(&self) -> Option<&[u8]> {7 pub fn as_slice(&self) -> Option<&[u8]> {
8 match self {8 match self {
9 PacketLineRef::Data(d) => Some(d),9 PacketLineRef::Data(d) => Some(d),
10 PacketLineRef::Flush | PacketLineRef::Delimiter | PacketLineRef::ResponseEnd => None,10 PacketLineRef::Flush | PacketLineRef::Delimiter | PacketLineRef::ResponseEnd => None,
11 }11 }
12 }12 }
13 /// Return this instance's [`as_slice()`][PacketLine::as_slice()] as [`BStr`].13 /// Return this instance's [`as_slice()`][PacketLineRef::as_slice()] as [`BStr`].
14 pub fn as_bstr(&self) -> Option<&BStr> {14 pub fn as_bstr(&self) -> Option<&BStr> {
15 self.as_slice().map(Into::into)15 self.as_slice().map(Into::into)
16 }16 }
17 /// Interpret this instance's [`as_slice()`][PacketLine::as_slice()] as [`Error`].17 /// Interpret this instance's [`as_slice()`][PacketLineRef::as_slice()] as [`ErrorRef`].
18 ///18 ///
19 /// This works for any data received in an error [channel][crate::Channel].19 /// This works for any data received in an error [channel][crate::Channel].
20 ///20 ///
21 /// Note that this creates an unchecked error using the slice verbatim, which is useful to [serialize it][Error::write_to()].21 /// Note that this creates an unchecked error using the slice verbatim, which is useful to [serialize it][ErrorRef::write_to()].
22 /// See [`check_error()`][PacketLine::check_error()] for a version that assures the error information is in the expected format.22 /// See [`check_error()`][PacketLineRef::check_error()] for a version that assures the error information is in the expected format.
23 pub fn as_error(&self) -> Option<ErrorRef<'_>> {23 pub fn as_error(&self) -> Option<ErrorRef<'_>> {
24 self.as_slice().map(ErrorRef)24 self.as_slice().map(ErrorRef)
25 }25 }
26 /// Check this instance's [`as_slice()`][PacketLine::as_slice()] is a valid [`Error`] and return it.26 /// Check this instance's [`as_slice()`][PacketLineRef::as_slice()] is a valid [`ErrorRef`] and return it.
27 ///27 ///
28 /// This works for any data received in an error [channel][crate::Channel].28 /// This works for any data received in an error [channel][crate::Channel].
29 pub fn check_error(&self) -> Option<ErrorRef<'_>> {29 pub fn check_error(&self) -> Option<ErrorRef<'_>> {
@@ -40,10 +40,10 @@ impl<'a> PacketLineRef<'a> { · 10 unmodified lines
40 self.as_slice().map(Into::into)40 self.as_slice().map(Into::into)
41 }41 }
42 42
43 /// Interpret the data in this [`slice`][PacketLine::as_slice()] as [`Band`] according to the given `kind` of channel.43 /// Interpret the data in this [`slice`][PacketLineRef::as_slice()] as [`BandRef`] according to the given `kind` of channel.
44 ///44 ///
45 /// Note that this is only relevant in a side-band channel.45 /// Note that this is only relevant in a side-band channel.
46 /// See [`decode_band()`][PacketLine::decode_band()] in case `kind` is unknown.46 /// See [`decode_band()`][PacketLineRef::decode_band()] in case `kind` is unknown.
47 pub fn as_band(&self, kind: Channel) -> Option<BandRef<'_>> {47 pub fn as_band(&self, kind: Channel) -> Option<BandRef<'_>> {
48 self.as_slice().map(|d| match kind {48 self.as_slice().map(|d| match kind {
49 Channel::Data => BandRef::Data(d),49 Channel::Data => BandRef::Data(d),
@@ -52,7 +52,7 @@ impl<'a> PacketLineRef<'a> { · 2 unmodified lines
52 })52 })
53 }53 }
54 54
55 /// Decode the band of this [`slice`][PacketLine::as_slice()], or panic if it is not actually a side-band line.55 /// Decode the band of this [`slice`][PacketLineRef::as_slice()], or panic if it is not actually a side-band line.
56 pub fn decode_band(&self) -> Result<BandRef<'_>, decode::band::Error> {56 pub fn decode_band(&self) -> Result<BandRef<'_>, decode::band::Error> {
57 let d = self.as_slice().ok_or(decode::band::Error::NonDataLine)?;57 let d = self.as_slice().ok_or(decode::band::Error::NonDataLine)?;
58 Ok(match d[0] {58 Ok(match d[0] {
git-packetline/src/read/mod.rs+1−1
@@ -10,7 +10,7 @@ type ExhaustiveOutcome<'a> = ( · 9 unmodified lines
10);10);
11 11
12/// Read pack lines one after another, without consuming more than needed from the underlying12/// Read pack lines one after another, without consuming more than needed from the underlying
13/// [`Read`][std::io::Read]. [`Flush`][PacketLine::Flush] lines cause the reader to stop producing lines forever,13/// [`Read`][std::io::Read]. [`Flush`][PacketLineRef::Flush] lines cause the reader to stop producing lines forever,
14/// leaving [`Read`][std::io::Read] at the start of whatever comes next.14/// leaving [`Read`][std::io::Read] at the start of whatever comes next.
15///15///
16/// This implementation tries hard not to allocate at all which leads to quite some added complexity and plenty of extra memory copies.16/// This implementation tries hard not to allocate at all which leads to quite some added complexity and plenty of extra memory copies.