Unified · Split
| @@ -250,7 +250,7 @@ impl<'event> SectionBody<'event> { · 249 unmodified lines | |||
| 250 | // We hit this lint because of the unreachable!() call may panic, but this | 250 | // We hit this lint because of the unreachable!() call may panic, but this |
| 251 | // is a clippy bug (rust-clippy#6699), so we allow this lint for this | 251 | // is a clippy bug (rust-clippy#6699), so we allow this lint for this |
| 252 | // function. | 252 | // function. |
| 253 | #[allow(clippy::clippy::missing_panics_doc)] | 253 | #[allow(clippy::missing_panics_doc)] |
| 254 | #[must_use] | 254 | #[must_use] |
| 255 | pub fn value(&self, key: &Key) -> Option<Cow<'event, [u8]>> { | 255 | pub fn value(&self, key: &Key) -> Option<Cow<'event, [u8]>> { |
| 256 | let range = self.get_value_range_by_key(key); | 256 | let range = self.get_value_range_by_key(key); |
| @@ -1843,12 +1843,14 @@ impl<'a> From<Parser<'a>> for GitConfig<'a> { · 1586 unmodified lines | |||
| 1843 | prev_section_header = Some(header); | 1843 | prev_section_header = Some(header); |
| 1844 | section_events = SectionBody::new(); | 1844 | section_events = SectionBody::new(); |
| 1845 | } | 1845 | } |
| 1846 | e @ Event::Key(_) | 1846 | e |
| 1847 | | e @ Event::Value(_) | 1847 | @ |
| 1848 | | e @ Event::ValueNotDone(_) | 1848 | (Event::Key(_) |
| 1849 | | e @ Event::ValueDone(_) | 1849 | | Event::Value(_) |
| 1850 | | e @ Event::KeyValueSeparator => section_events.0.push(e), | 1850 | | Event::ValueNotDone(_) |
| 1851 | e @ Event::Comment(_) | e @ Event::Newline(_) | e @ Event::Whitespace(_) => { | 1851 | | Event::ValueDone(_) |
| 1852 | | Event::KeyValueSeparator) => section_events.0.push(e), | ||
| 1853 | e @ (Event::Comment(_) | Event::Newline(_) | Event::Whitespace(_)) => { | ||
| 1852 | section_events.0.push(e); | 1854 | section_events.0.push(e); |
| 1853 | } | 1855 | } |
| 1854 | } | 1856 | } |
| @@ -549,7 +549,7 @@ impl Integer { · 548 unmodified lines | |||
| 549 | /// non-UTF-8 sequences are present or a UTF-8 representation can't be | 549 | /// non-UTF-8 sequences are present or a UTF-8 representation can't be |
| 550 | /// guaranteed. | 550 | /// guaranteed. |
| 551 | #[must_use] | 551 | #[must_use] |
| 552 | pub fn to_vec(&self) -> Vec<u8> { | 552 | pub fn to_vec(self) -> Vec<u8> { |
| 553 | self.into() | 553 | self.into() |
| 554 | } | 554 | } |
| 555 | } | 555 | } |
| @@ -63,7 +63,7 @@ impl ObjectId { · 62 unmodified lines | |||
| 63 | /// Return ourselves as array of 40 hexadecimal bytes. | 63 | /// Return ourselves as array of 40 hexadecimal bytes. |
| 64 | /// | 64 | /// |
| 65 | /// Panics if this instance is not a sha1 hash. | 65 | /// Panics if this instance is not a sha1 hash. |
| 66 | pub fn to_sha1_hex(&self) -> [u8; SIZE_OF_SHA1_DIGEST * 2] { | 66 | pub fn to_sha1_hex(self) -> [u8; SIZE_OF_SHA1_DIGEST * 2] { |
| 67 | match self { | 67 | match self { |
| 68 | Self::Sha1(b) => { | 68 | Self::Sha1(b) => { |
| 69 | let mut hex_buf = [0u8; 40]; | 69 | let mut hex_buf = [0u8; 40]; |
| @@ -76,7 +76,7 @@ impl ObjectId { · 6 unmodified lines | |||
| 76 | /// Return ourselves as hexadecimal string with a length of 40 bytes. | 76 | /// Return ourselves as hexadecimal string with a length of 40 bytes. |
| 77 | /// | 77 | /// |
| 78 | /// Panics if this instance is not a sha1 hash. | 78 | /// Panics if this instance is not a sha1 hash. |
| 79 | pub fn to_sha1_hex_string(&self) -> String { | 79 | pub fn to_sha1_hex_string(self) -> String { |
| 80 | let buf = self.to_sha1_hex(); | 80 | let buf = self.to_sha1_hex(); |
| 81 | std::str::from_utf8(&buf).expect("hex is valid UTF-8").to_string() | 81 | std::str::from_utf8(&buf).expect("hex is valid UTF-8").to_string() |
| 82 | } | 82 | } |
| @@ -46,7 +46,7 @@ impl Tag { · 45 unmodified lines | |||
| 46 | /// Writes the encoded tag to `out`. | 46 | /// Writes the encoded tag to `out`. |
| 47 | pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> { | 47 | pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> { |
| 48 | encode::trusted_header_id(b"object", &self.target, &mut out)?; | 48 | encode::trusted_header_id(b"object", &self.target, &mut out)?; |
| 49 | encode::trusted_header_field(b"type", self.target_kind.to_bytes(), &mut out)?; | 49 | encode::trusted_header_field(b"type", self.target_kind.as_bytes(), &mut out)?; |
| 50 | encode::header_field(b"tag", validated_name(self.name.as_ref())?, &mut out)?; | 50 | encode::header_field(b"tag", validated_name(self.name.as_ref())?, &mut out)?; |
| 51 | if let Some(tagger) = &self.signature { | 51 | if let Some(tagger) = &self.signature { |
| 52 | encode::trusted_header_signature(b"tagger", tagger, &mut out)?; | 52 | encode::trusted_header_signature(b"tagger", tagger, &mut out)?; |
| @@ -87,7 +87,7 @@ impl Kind { · 86 unmodified lines | |||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | /// Return the name of `self` for use in serialized loose git objects. | 89 | /// Return the name of `self` for use in serialized loose git objects. |
| 90 | pub fn to_bytes(&self) -> &[u8] { | 90 | pub fn as_bytes(&self) -> &[u8] { |
| 91 | match self { | 91 | match self { |
| 92 | Kind::Tree => b"tree", | 92 | Kind::Tree => b"tree", |
| 93 | Kind::Commit => b"commit", | 93 | Kind::Commit => b"commit", |
| @@ -99,7 +99,7 @@ impl Kind { · 5 unmodified lines | |||
| 99 | 99 | ||
| 100 | impl fmt::Display for Kind { | 100 | impl fmt::Display for Kind { |
| 101 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 101 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 102 | f.write_str(std::str::from_utf8(self.to_bytes()).expect("Converting Kind name to utf8")) | 102 | f.write_str(std::str::from_utf8(self.as_bytes()).expect("Converting Kind name to utf8")) |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| @@ -44,7 +44,7 @@ impl Header { · 43 unmodified lines | |||
| 44 | pack_offset.checked_sub(distance) | 44 | pack_offset.checked_sub(distance) |
| 45 | } | 45 | } |
| 46 | /// Convert the header's object kind into [`git_object::Kind`] if possible | 46 | /// Convert the header's object kind into [`git_object::Kind`] if possible |
| 47 | pub fn to_kind(&self) -> Option<git_object::Kind> { | 47 | pub fn as_kind(&self) -> Option<git_object::Kind> { |
| 48 | use git_object::Kind::*; | 48 | use git_object::Kind::*; |
| 49 | Some(match self { | 49 | Some(match self { |
| 50 | Header::Tree => Tree, | 50 | Header::Tree => Tree, |
| @@ -55,7 +55,7 @@ impl Header { · 4 unmodified lines | |||
| 55 | }) | 55 | }) |
| 56 | } | 56 | } |
| 57 | /// Convert this header's object kind into the packs internal representation | 57 | /// Convert this header's object kind into the packs internal representation |
| 58 | pub fn to_type_id(&self) -> u8 { | 58 | pub fn as_type_id(&self) -> u8 { |
| 59 | use Header::*; | 59 | use Header::*; |
| 60 | match self { | 60 | match self { |
| 61 | Blob => BLOB, | 61 | Blob => BLOB, |
| @@ -81,10 +81,10 @@ impl Header { · 19 unmodified lines | |||
| 81 | /// | 81 | /// |
| 82 | /// Returns the amount of bytes written to `out`. | 82 | /// Returns the amount of bytes written to `out`. |
| 83 | /// `decompressed_size_in_bytes` is the full size in bytes of the object that this header represents | 83 | /// `decompressed_size_in_bytes` is the full size in bytes of the object that this header represents |
| 84 | pub fn to_write(&self, decompressed_size_in_bytes: u64, mut out: impl io::Write) -> io::Result<usize> { | 84 | pub fn write_to(&self, decompressed_size_in_bytes: u64, mut out: impl io::Write) -> io::Result<usize> { |
| 85 | let mut size = decompressed_size_in_bytes; | 85 | let mut size = decompressed_size_in_bytes; |
| 86 | let mut written = 1; | 86 | let mut written = 1; |
| 87 | let mut c: u8 = (self.to_type_id() << 4) | (size as u8 & 0b0000_1111); | 87 | let mut c: u8 = (self.as_type_id() << 4) | (size as u8 & 0b0000_1111); |
| 88 | size >>= 4; | 88 | size >>= 4; |
| 89 | while size != 0 { | 89 | while size != 0 { |
| 90 | out.write_all(&[c | 0b1000_0000])?; | 90 | out.write_all(&[c | 0b1000_0000])?; |
| @@ -36,7 +36,7 @@ impl Entry { · 35 unmodified lines | |||
| 36 | /// The amount of bytes used to describe this entry in the pack. The header starts at [`Self::pack_offset()`] | 36 | /// The amount of bytes used to describe this entry in the pack. The header starts at [`Self::pack_offset()`] |
| 37 | pub fn header_size(&self) -> usize { | 37 | pub fn header_size(&self) -> usize { |
| 38 | self.header | 38 | self.header |
| 39 | .to_write(self.decompressed_size, io::sink()) | 39 | .write_to(self.decompressed_size, io::sink()) |
| 40 | .expect("io::sink() to never fail") | 40 | .expect("io::sink() to never fail") |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| @@ -153,7 +153,7 @@ impl File { · 152 unmodified lines | |||
| 153 | ); | 153 | ); |
| 154 | self.decompress_entry(&entry, out.as_mut_slice()).map(|consumed_input| { | 154 | self.decompress_entry(&entry, out.as_mut_slice()).map(|consumed_input| { |
| 155 | Outcome::from_object_entry( | 155 | Outcome::from_object_entry( |
| 156 | entry.header.to_kind().expect("a non-delta entry"), | 156 | entry.header.as_kind().expect("a non-delta entry"), |
| 157 | &entry, | 157 | &entry, |
| 158 | consumed_input, | 158 | consumed_input, |
| 159 | ) | 159 | ) |
| @@ -314,7 +314,7 @@ impl File { · 154 unmodified lines | |||
| 314 | if base_buffer_size.is_none() { | 314 | if base_buffer_size.is_none() { |
| 315 | let base_entry = cursor; | 315 | let base_entry = cursor; |
| 316 | debug_assert!(!base_entry.header.is_delta()); | 316 | debug_assert!(!base_entry.header.is_delta()); |
| 317 | object_kind = base_entry.header.to_kind(); | 317 | object_kind = base_entry.header.as_kind(); |
| 318 | let packed_size = self.decompress_entry_from_data_offset(base_entry.data_offset, out)?; | 318 | let packed_size = self.decompress_entry_from_data_offset(base_entry.data_offset, out)?; |
| 319 | cache.put( | 319 | cache.put( |
| 320 | self.id, | 320 | self.id, |
| @@ -138,7 +138,7 @@ where · 137 unmodified lines | |||
| 138 | 138 | ||
| 139 | let crc32 = if self.compressed.crc32() { | 139 | let crc32 = if self.compressed.crc32() { |
| 140 | let mut header_buf = [0u8; 32]; | 140 | let mut header_buf = [0u8; 32]; |
| 141 | let header_len = entry.header.to_write(bytes_copied, header_buf.as_mut())?; | 141 | let header_len = entry.header.write_to(bytes_copied, header_buf.as_mut())?; |
| 142 | let state = git_features::hash::crc32_update(0, &header_buf[..header_len]); | 142 | let state = git_features::hash::crc32_update(0, &header_buf[..header_len]); |
| 143 | Some(git_features::hash::crc32_update(state, &compressed)) | 143 | Some(git_features::hash::crc32_update(state, &compressed)) |
| 144 | } else { | 144 | } else { |
| @@ -100,7 +100,7 @@ where · 99 unmodified lines | |||
| 100 | let header = entry.to_entry_header(self.entry_version, |_index_offset| { | 100 | let header = entry.to_entry_header(self.entry_version, |_index_offset| { |
| 101 | unimplemented!("a way to calculate pack offsets from object index offsets") | 101 | unimplemented!("a way to calculate pack offsets from object index offsets") |
| 102 | }); | 102 | }); |
| 103 | written += header.to_write(entry.decompressed_size as u64, &mut self.output)? as u64; | 103 | written += header.write_to(entry.decompressed_size as u64, &mut self.output)? as u64; |
| 104 | written += std::io::copy(&mut &*entry.compressed_data, &mut self.output)? as u64; | 104 | written += std::io::copy(&mut &*entry.compressed_data, &mut self.output)? as u64; |
| 105 | } | 105 | } |
| 106 | } | 106 | } |
| @@ -80,7 +80,7 @@ impl output::Entry { · 79 unmodified lines | |||
| 80 | if pack_entry.header.is_base() { | 80 | if pack_entry.header.is_base() { |
| 81 | Some(Ok(output::Entry { | 81 | Some(Ok(output::Entry { |
| 82 | id: count.id.to_owned(), | 82 | id: count.id.to_owned(), |
| 83 | object_kind: pack_entry.header.to_kind().expect("valid object only"), | 83 | object_kind: pack_entry.header.as_kind().expect("valid object only"), |
| 84 | kind: output::entry::Kind::Base, | 84 | kind: output::entry::Kind::Base, |
| 85 | decompressed_size: pack_entry.decompressed_size as usize, | 85 | decompressed_size: pack_entry.decompressed_size as usize, |
| 86 | compressed_data: entry.data[pack_entry.data_offset as usize..].to_owned(), | 86 | compressed_data: entry.data[pack_entry.data_offset as usize..].to_owned(), |
| @@ -86,7 +86,7 @@ impl index::File { · 85 unmodified lines | |||
| 86 | state: (ref mut processor, ref mut header_buf), | 86 | state: (ref mut processor, ref mut header_buf), |
| 87 | level, | 87 | level, |
| 88 | }| { | 88 | }| { |
| 89 | let object_kind = pack_entry.header.to_kind().expect("non-delta object"); | 89 | let object_kind = pack_entry.header.as_kind().expect("non-delta object"); |
| 90 | data.level = level; | 90 | data.level = level; |
| 91 | data.decompressed_size = pack_entry.decompressed_size; | 91 | data.decompressed_size = pack_entry.decompressed_size; |
| 92 | data.object_kind = object_kind; | 92 | data.object_kind = object_kind; |
| @@ -230,7 +230,7 @@ fn modify_base( · 229 unmodified lines | |||
| 230 | git_hash::ObjectId::from(write.hash.digest()) | 230 | git_hash::ObjectId::from(write.hash.digest()) |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | let object_kind = pack_entry.header.to_kind().expect("base object as source of iteration"); | 233 | let object_kind = pack_entry.header.as_kind().expect("base object as source of iteration"); |
| 234 | let id = compute_hash(object_kind, &decompressed, hash); | 234 | let id = compute_hash(object_kind, &decompressed, hash); |
| 235 | entry.id = id; | 235 | entry.id = id; |
| 236 | } | 236 | } |
| @@ -29,7 +29,7 @@ mod new_from_header { · 28 unmodified lines | |||
| 29 | let entry = entry?; | 29 | let entry = entry?; |
| 30 | 30 | ||
| 31 | let mut buf = Vec::<u8>::new(); | 31 | let mut buf = Vec::<u8>::new(); |
| 32 | entry.header.to_write(entry.decompressed_size, &mut buf)?; | 32 | entry.header.write_to(entry.decompressed_size, &mut buf)?; |
| 33 | let new_entry = pack::data::Entry::from_bytes(&buf, entry.pack_offset); | 33 | let new_entry = pack::data::Entry::from_bytes(&buf, entry.pack_offset); |
| 34 | 34 | ||
| 35 | assert_eq!( | 35 | assert_eq!( |
| @@ -9,7 +9,7 @@ impl<'a> Band<'a> { · 8 unmodified lines | |||
| 9 | /// Serialize this instance to `out`, returning the amount of bytes written. | 9 | /// Serialize this instance to `out`, returning the amount of bytes written. |
| 10 | /// | 10 | /// |
| 11 | /// The data written to `out` can be decoded with [`Borrowed::decode_band()]`. | 11 | /// The data written to `out` can be decoded with [`Borrowed::decode_band()]`. |
| 12 | pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> { | 12 | pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> { |
| 13 | match self { | 13 | match self { |
| 14 | Band::Data(d) => encode::band_to_write(Channel::Data, d, out), | 14 | Band::Data(d) => encode::band_to_write(Channel::Data, d, out), |
| 15 | Band::Progress(d) => encode::band_to_write(Channel::Progress, d, out), | 15 | Band::Progress(d) => encode::band_to_write(Channel::Progress, d, out), |
| @@ -20,7 +20,7 @@ impl<'a> Band<'a> { · 4 unmodified lines | |||
| 20 | 20 | ||
| 21 | impl<'a> Text<'a> { | 21 | impl<'a> Text<'a> { |
| 22 | /// Serialize this instance to `out`, appending a newline if there is none, returning the amount of bytes written. | 22 | /// Serialize this instance to `out`, appending a newline if there is none, returning the amount of bytes written. |
| 23 | pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> { | 23 | pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> { |
| 24 | encode::text_to_write(self.0, out) | 24 | encode::text_to_write(self.0, out) |
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| @@ -29,14 +29,14 @@ impl<'a> Error<'a> { · 2 unmodified lines | |||
| 29 | /// Serialize this line as error to `out`. | 29 | /// Serialize this line as error to `out`. |
| 30 | /// | 30 | /// |
| 31 | /// This includes a marker to allow decoding it outside of a side-band channel, returning the amount of bytes written. | 31 | /// This includes a marker to allow decoding it outside of a side-band channel, returning the amount of bytes written. |
| 32 | pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> { | 32 | pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> { |
| 33 | encode::error_to_write(self.0, out) | 33 | encode::error_to_write(self.0, out) |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | impl<'a> PacketLine<'a> { | 37 | impl<'a> PacketLine<'a> { |
| 38 | /// Serialize this instance to `out` in git `packetline` format, returning the amount of bytes written to `out`. | 38 | /// Serialize this instance to `out` in git `packetline` format, returning the amount of bytes written to `out`. |
| 39 | pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> { | 39 | pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> { |
| 40 | match self { | 40 | match self { |
| 41 | PacketLine::Data(d) => encode::data_to_write(d, out), | 41 | PacketLine::Data(d) => encode::data_to_write(d, out), |
| 42 | PacketLine::Flush => encode::flush_to_write(out), | 42 | PacketLine::Flush => encode::flush_to_write(out), |
| @@ -33,7 +33,7 @@ impl<'a> PacketLine<'a> { · 32 unmodified lines | |||
| 33 | /// | 33 | /// |
| 34 | /// Note that this creates an unchecked error using the slice verbatim, which is useful to [serialize it][Error::to_write()]. | 34 | /// Note that this creates an unchecked error using the slice verbatim, which is useful to [serialize it][Error::to_write()]. |
| 35 | /// See [`check_error()`][PacketLine::check_error()] for a version that assures the error information is in the expected format. | 35 | /// See [`check_error()`][PacketLine::check_error()] for a version that assures the error information is in the expected format. |
| 36 | pub fn to_error(&self) -> Option<Error<'_>> { | 36 | pub fn as_error(&self) -> Option<Error<'_>> { |
| 37 | self.as_slice().map(Error) | 37 | self.as_slice().map(Error) |
| 38 | } | 38 | } |
| 39 | /// Check this instance's [`as_slice()`][PacketLine::as_slice()] is a valid [`Error`] and return it. | 39 | /// Check this instance's [`as_slice()`][PacketLine::as_slice()] is a valid [`Error`] and return it. |
| @@ -49,7 +49,7 @@ impl<'a> PacketLine<'a> { · 9 unmodified lines | |||
| 49 | }) | 49 | }) |
| 50 | } | 50 | } |
| 51 | /// Return this instance as text, with the trailing newline truncated if present. | 51 | /// Return this instance as text, with the trailing newline truncated if present. |
| 52 | pub fn to_text(&self) -> Option<Text<'_>> { | 52 | pub fn as_text(&self) -> Option<Text<'_>> { |
| 53 | self.as_slice().map(Into::into) | 53 | self.as_slice().map(Into::into) |
| 54 | } | 54 | } |
| 55 | 55 | ||
| @@ -57,7 +57,7 @@ impl<'a> PacketLine<'a> { · 1 unmodified line | |||
| 57 | /// | 57 | /// |
| 58 | /// Note that this is only relevant in a side-band channel. | 58 | /// Note that this is only relevant in a side-band channel. |
| 59 | /// See [`decode_band()`][PacketLine::decode_band()] in case `kind` is unknown. | 59 | /// See [`decode_band()`][PacketLine::decode_band()] in case `kind` is unknown. |
| 60 | pub fn to_band(&self, kind: Channel) -> Option<Band<'_>> { | 60 | pub fn as_band(&self, kind: Channel) -> Option<Band<'_>> { |
| 61 | self.as_slice().map(|d| match kind { | 61 | self.as_slice().map(|d| match kind { |
| 62 | Channel::Data => Band::Data(d), | 62 | Channel::Data => Band::Data(d), |
| 63 | Channel::Progress => Band::Progress(d), | 63 | Channel::Progress => Band::Progress(d), |
| @@ -29,11 +29,11 @@ mod streaming { · 28 unmodified lines | |||
| 29 | #[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))] | 29 | #[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))] |
| 30 | async fn trailing_line_feeds_are_removed_explicitly() -> crate::Result { | 30 | async fn trailing_line_feeds_are_removed_explicitly() -> crate::Result { |
| 31 | let line = decode::all_at_once(b"0006a\n")?; | 31 | let line = decode::all_at_once(b"0006a\n")?; |
| 32 | assert_eq!(line.to_text().expect("text").0.as_bstr(), b"a".as_bstr()); | 32 | assert_eq!(line.as_text().expect("text").0.as_bstr(), b"a".as_bstr()); |
| 33 | let mut out = Vec::new(); | 33 | let mut out = Vec::new(); |
| 34 | line.to_text() | 34 | line.as_text() |
| 35 | .expect("text") | 35 | .expect("text") |
| 36 | .to_write(&mut out) | 36 | .write_to(&mut out) |
| 37 | .await | 37 | .await |
| 38 | .expect("write to memory works"); | 38 | .expect("write to memory works"); |
| 39 | assert_eq!(out, b"0006a\n", "it appends a newline in text mode"); | 39 | assert_eq!(out, b"0006a\n", "it appends a newline in text mode"); |
| @@ -49,7 +49,7 @@ mod streaming { · 9 unmodified lines | |||
| 49 | (PacketLine::Data(b"hello there"), 15), | 49 | (PacketLine::Data(b"hello there"), 15), |
| 50 | ] { | 50 | ] { |
| 51 | let mut out = Vec::new(); | 51 | let mut out = Vec::new(); |
| 52 | line.to_write(&mut out).await?; | 52 | line.write_to(&mut out).await?; |
| 53 | assert_complete(streaming(&out), *bytes, *line)?; | 53 | assert_complete(streaming(&out), *bytes, *line)?; |
| 54 | } | 54 | } |
| 55 | Ok(()) | 55 | Ok(()) |
| @@ -59,9 +59,9 @@ mod streaming { · 3 unmodified lines | |||
| 59 | async fn error_line() -> crate::Result { | 59 | async fn error_line() -> crate::Result { |
| 60 | let mut out = Vec::new(); | 60 | let mut out = Vec::new(); |
| 61 | PacketLine::Data(b"the error") | 61 | PacketLine::Data(b"the error") |
| 62 | .to_error() | 62 | .as_error() |
| 63 | .expect("data line") | 63 | .expect("data line") |
| 64 | .to_write(&mut out) | 64 | .write_to(&mut out) |
| 65 | .await?; | 65 | .await?; |
| 66 | let line = decode::all_at_once(&out)?; | 66 | let line = decode::all_at_once(&out)?; |
| 67 | assert_eq!(line.check_error().expect("err").0, b"the error"); | 67 | assert_eq!(line.check_error().expect("err").0, b"the error"); |
| @@ -73,9 +73,9 @@ mod streaming { · 5 unmodified lines | |||
| 73 | for channel in &[Channel::Data, Channel::Error, Channel::Progress] { | 73 | for channel in &[Channel::Data, Channel::Error, Channel::Progress] { |
| 74 | let mut out = Vec::new(); | 74 | let mut out = Vec::new(); |
| 75 | let band = PacketLine::Data(b"band data") | 75 | let band = PacketLine::Data(b"band data") |
| 76 | .to_band(*channel) | 76 | .as_band(*channel) |
| 77 | .expect("data is valid for band"); | 77 | .expect("data is valid for band"); |
| 78 | band.to_write(&mut out).await?; | 78 | band.write_to(&mut out).await?; |
| 79 | let line = decode::all_at_once(&out)?; | 79 | let line = decode::all_at_once(&out)?; |
| 80 | assert_eq!(line.decode_band().expect("valid band"), band); | 80 | assert_eq!(line.decode_band().expect("valid band"), band); |
| 81 | } | 81 | } |
| @@ -60,22 +60,22 @@ impl<'a> RequestWriter<'a> { · 59 unmodified lines | |||
| 60 | match message { | 60 | match message { |
| 61 | MessageKind::Flush => { | 61 | MessageKind::Flush => { |
| 62 | git_packetline::PacketLine::Flush | 62 | git_packetline::PacketLine::Flush |
| 63 | .to_write(self.writer.inner_mut()) | 63 | .write_to(self.writer.inner_mut()) |
| 64 | .await | 64 | .await |
| 65 | } | 65 | } |
| 66 | MessageKind::Delimiter => { | 66 | MessageKind::Delimiter => { |
| 67 | git_packetline::PacketLine::Delimiter | 67 | git_packetline::PacketLine::Delimiter |
| 68 | .to_write(self.writer.inner_mut()) | 68 | .write_to(self.writer.inner_mut()) |
| 69 | .await | 69 | .await |
| 70 | } | 70 | } |
| 71 | MessageKind::ResponseEnd => { | 71 | MessageKind::ResponseEnd => { |
| 72 | git_packetline::PacketLine::ResponseEnd | 72 | git_packetline::PacketLine::ResponseEnd |
| 73 | .to_write(self.writer.inner_mut()) | 73 | .write_to(self.writer.inner_mut()) |
| 74 | .await | 74 | .await |
| 75 | } | 75 | } |
| 76 | MessageKind::Text(t) => { | 76 | MessageKind::Text(t) => { |
| 77 | git_packetline::immutable::Text::from(t) | 77 | git_packetline::immutable::Text::from(t) |
| 78 | .to_write(self.writer.inner_mut()) | 78 | .write_to(self.writer.inner_mut()) |
| 79 | .await | 79 | .await |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| @@ -46,10 +46,10 @@ impl<'a> RequestWriter<'a> { · 45 unmodified lines | |||
| 46 | /// Write the given message as packet line. | 46 | /// Write the given message as packet line. |
| 47 | pub fn write_message(&mut self, message: MessageKind) -> io::Result<()> { | 47 | pub fn write_message(&mut self, message: MessageKind) -> io::Result<()> { |
| 48 | match message { | 48 | match message { |
| 49 | MessageKind::Flush => git_packetline::PacketLine::Flush.to_write(self.writer.inner_mut()), | 49 | MessageKind::Flush => git_packetline::PacketLine::Flush.write_to(self.writer.inner_mut()), |
| 50 | MessageKind::Delimiter => git_packetline::PacketLine::Delimiter.to_write(self.writer.inner_mut()), | 50 | MessageKind::Delimiter => git_packetline::PacketLine::Delimiter.write_to(self.writer.inner_mut()), |
| 51 | MessageKind::ResponseEnd => git_packetline::PacketLine::ResponseEnd.to_write(self.writer.inner_mut()), | 51 | MessageKind::ResponseEnd => git_packetline::PacketLine::ResponseEnd.write_to(self.writer.inner_mut()), |
| 52 | MessageKind::Text(t) => git_packetline::immutable::Text::from(t).to_write(self.writer.inner_mut()), | 52 | MessageKind::Text(t) => git_packetline::immutable::Text::from(t).write_to(self.writer.inner_mut()), |
| 53 | } | 53 | } |
| 54 | .map(|_| ()) | 54 | .map(|_| ()) |
| 55 | } | 55 | } |
| @@ -139,7 +139,7 @@ impl Capabilities { · 138 unmodified lines | |||
| 139 | capabilities_or_version: &'a git_packetline::PacketLine<'_>, | 139 | capabilities_or_version: &'a git_packetline::PacketLine<'_>, |
| 140 | ) -> Result<(git_packetline::immutable::Text<'a>, Protocol), client::Error> { | 140 | ) -> Result<(git_packetline::immutable::Text<'a>, Protocol), client::Error> { |
| 141 | let first_line = capabilities_or_version | 141 | let first_line = capabilities_or_version |
| 142 | .to_text() | 142 | .as_text() |
| 143 | .ok_or(client::Error::ExpectedLine("text"))?; | 143 | .ok_or(client::Error::ExpectedLine("text"))?; |
| 144 | 144 | ||
| 145 | let line = first_line.as_bstr(); | 145 | let line = first_line.as_bstr(); |