Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
@@ -0,0 +1 @@
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{"CHANGELOG.md":"0941053f46ff2a05546dcc30f89c7c8aea0ffe5c61453e751197f452b566de3b","Cargo.toml":"a350dd8f6cfac0882832935b47259b4cd11e63f799a4ffea62fa6c400cca6670","Cargo.toml.orig":"959a4959294f6d140e8b63c625a156733f6b678d6df94e2dd1979055631e916a","README.md":"3af55ed26900ec256f0fc2600d6fa40ea20927ca57728ebe21a15c3d8af950c1","rust-toolchain":"58bea07cb6d97f9cfcd5c8f98b1feca0fb81cce5b0bf29a8e70ed2641956e9a6","src/deser.rs":"670ddfd7d84310a43985da10282017d57757e8875f5215f49604e866678b7a09","src/lib.rs":"add41210d56fa002974e070d88944d4a58597f30cefaa6743f5b2d5ca69ecd17"},"package":"0d75b8252ed252f881d1dc4482ae3c3854df6ee8183c1906bac50ff358f4f89f"}
+19
View File
@@ -0,0 +1,19 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
<!-- next-header -->
## [Unreleased] - ReleaseDate
## [0.1.1] - 2020-11-18
### Fixed
- Exposed the `frames` within a parsed backtrace so this crate is actually
useful...
<!-- next-url -->
[Unreleased]: https://github.com/yaahc/btparse/compare/v0.1.1...HEAD
[0.1.1]: https://github.com/yaahc/btparse/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/yaahc/btparse/releases/tag/v0.1.0
+76
View File
@@ -0,0 +1,76 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "btparse-stable"
version = "0.1.2"
authors = [
"Jane Lusby <jlusby@yaah.dev>",
"Dotan Nahum <dotan@rng0.io>",
]
description = """
A minimal deserializer for inspecting `std::backtrace::Backtrace`'s Debug format.
"""
homepage = "https://github.com/jondot/btparse"
documentation = "https://docs.rs/btparse"
readme = "README.md"
keywords = [
"backtrace",
"std",
"parse",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/jondot/btparse"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
replace = "{{version}}"
search = "Unreleased"
[[package.metadata.release.pre-release-replacements]]
exactly = 1
file = "src/lib.rs"
replace = "#![doc(html_root_url = \"https://docs.rs/{{crate_name}}/{{version}}\")]"
search = '#!\[doc\(html_root_url.*'
[[package.metadata.release.pre-release-replacements]]
exactly = 1
file = "CHANGELOG.md"
replace = "...{{tag_name}}"
search = '\.\.\.HEAD'
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
replace = "{{date}}"
search = "ReleaseDate"
[[package.metadata.release.pre-release-replacements]]
exactly = 1
file = "CHANGELOG.md"
replace = """
<!-- next-header -->
## [Unreleased] - ReleaseDate"""
search = "<!-- next-header -->"
[[package.metadata.release.pre-release-replacements]]
exactly = 1
file = "CHANGELOG.md"
replace = """
<!-- next-url -->
[Unreleased]: https://github.com/yaahc/{{crate_name}}/compare/{{tag_name}}...HEAD"""
search = "<!-- next-url -->"
[dependencies]
[dev-dependencies.eyre]
version = "0.3.8"
+55
View File
@@ -0,0 +1,55 @@
[package]
name = "btparse-stable"
version = "0.1.2"
authors = ["Jane Lusby <jlusby@yaah.dev>", "Dotan Nahum <dotan@rng0.io>"]
edition = "2018"
repository = "https://github.com/jondot/btparse"
homepage = "https://github.com/jondot/btparse"
documentation = "https://docs.rs/btparse"
description = """
A minimal deserializer for inspecting `std::backtrace::Backtrace`'s Debug format.
"""
keywords = ["backtrace", "std", "parse"]
license = "MIT OR Apache-2.0"
readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[dev-dependencies]
eyre = "0.3.8"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "Unreleased"
replace = "{{version}}"
[[package.metadata.release.pre-release-replacements]]
file = "src/lib.rs"
search = "#!\\[doc\\(html_root_url.*"
replace = "#![doc(html_root_url = \"https://docs.rs/{{crate_name}}/{{version}}\")]"
exactly = 1
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "\\.\\.\\.HEAD"
replace = "...{{tag_name}}"
exactly = 1
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "ReleaseDate"
replace = "{{date}}"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "<!-- next-header -->"
replace = "<!-- next-header -->\n\n## [Unreleased] - ReleaseDate"
exactly = 1
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "<!-- next-url -->"
replace = "<!-- next-url -->\n[Unreleased]: https://github.com/yaahc/{{crate_name}}/compare/{{tag_name}}...HEAD"
exactly = 1
+53
View File
@@ -0,0 +1,53 @@
btparse
=======
A minimal deserializer for inspecting `std::backtrace::Backtrace`'s Debug format.
## Overview
For the time being, the rust standard library is exporting the smallest API
surface for `std::backtrace::Backtrace` that it possibly can, and only allows
inspection via the `Debug` and `Display` traits. However, in order to provide
custom formatting for backtraces, libraries like `color-backtrace` need to be
able to iterate over the frames of a backtrace and access its various members
like the filename and line number.
This library provides a stop-gap solution. Until std eventually exports a
stable iterator interface to backtrace frames this library will attempt to
provide best effort parsing of backtrace's unstable Debug output. This will
allow libraries like `color-backtrace` to provide unstable support for
`std::backtrace::Backtrace` until it eventually stabilizes.
Once std eventually stabilizes this library will update the internals to depend
upon the provided iterator API instead of potentially fragile parsing.
<br>
# Usage
```
cargo add btparse
```
```rust
let bt = std::backtrace::Backtrace::capture();
let bt_parsed = btparse::deserialize(&bt);
```
<br>
#### License
<sup>
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
</sup>
<br>
<sub>
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.
</sub>
+1
View File
@@ -0,0 +1 @@
nightly
+257
View File
@@ -0,0 +1,257 @@
//! Deserialization helper functions
use crate::{Error, Frame, Kind};
pub(crate) fn close_bracket(bt: &str) -> Result<&str, Error> {
start(bt, "]")
}
pub(crate) fn frame(bt: &str) -> Result<(&str, Frame), Error> {
let (bt, frame) = delimited(bt, "{", "}")?;
let frame = start(frame, "fn: ")?;
let file_match = ", file: ";
let file_start = frame.find(file_match);
let line_match = ", line: ";
let line_start = frame.find(line_match);
let fn_end = file_start.or(line_start).unwrap_or_else(|| frame.len());
let function = frame[..fn_end].trim_matches('"').to_string();
let file = file_start
.map(|start| {
(
start + file_match.len(),
line_start.unwrap_or_else(|| frame.len()),
)
})
.map(|(start, end)| &frame[start..end])
.map(|file| file.trim_matches('"'))
.map(ToString::to_string);
let line = line_start
.map(|start| (start + line_match.len(), frame.len()))
.map(|(start, end)| &frame[start..end])
.map(|line| {
line.parse::<usize>()
.map_err(|source| Kind::LineParse(line.into(), source))
})
.transpose()?;
Ok((
bt,
Frame {
function,
line,
file,
},
))
}
fn delimited<'a>(bt: &'a str, start: &str, end: &str) -> Result<(&'a str, &'a str), Error> {
let mut depth = 1;
let start_len = start.chars().count();
if !bt.starts_with(start) {
Err(Kind::InvalidInput {
expected: start.into(),
found: bt.chars().take(start_len).collect(),
})?;
}
let start_ind = start_len;
let mut end_ind = None;
for (ind, _) in bt.char_indices().skip(start_len) {
match bt.get(ind..) {
Some(next) if next.starts_with(start) => depth += 1,
Some(next) if next.starts_with(end) => depth -= 1,
Some(_) => (),
None => unimplemented!(),
}
if depth == 0 {
end_ind = Some(ind);
break;
}
}
if let Some(end_ind) = end_ind {
let end = end_ind + end.len();
Ok((&bt[end..], &bt[start_ind..end_ind].trim()))
} else {
unimplemented!()
}
}
pub(crate) fn header(bt: &str) -> Result<&str, Error> {
let mut parts = bt.splitn(2, '[');
let header = parts.next().unwrap();
match header {
"Backtrace " => (),
"<disabled>" | "disabled backtrace" => Err(Kind::Disabled)?,
"unsupported backtrace" => Err(Kind::Unsupported)?,
_ => Err(Kind::UnexpectedInput(header.into()))?,
}
Ok(parts.next().unwrap())
}
fn start<'a>(bt: &'a str, expected: &str) -> Result<&'a str, Error> {
if bt.starts_with(expected) {
return Ok(bt.trim_start_matches(expected));
}
Err(Kind::InvalidInput {
found: bt.chars().take(expected.chars().count()).collect(),
expected: expected.to_string(),
})?
}
pub(crate) fn trailing_comma(bt: &str) -> (&str, bool) {
start(bt, ", ").map(|bt| (bt, true)).unwrap_or((bt, false))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn frame_test() -> eyre::Result<()> {
let input = "{fn: \"function_name\", file: \"file_name\", line: 10} extra input";
let (input, f) = frame(input)?;
assert_eq!(" extra input", input);
assert_eq!(
Frame {
function: "function_name".into(),
file: Some("file_name".into()),
line: Some(10)
},
f
);
let input = "{fn: \"function_name\", line: 10} extra input";
let (input, f) = frame(input)?;
assert_eq!(" extra input", input);
assert_eq!(
Frame {
function: "function_name".into(),
file: None,
line: Some(10)
},
f
);
let input = "{fn: \"function_name\", file: \"file_name\"} extra input";
let (input, f) = frame(input)?;
assert_eq!(" extra input", input);
assert_eq!(
Frame {
function: "function_name".into(),
file: Some("file_name".into()),
line: None,
},
f
);
let input = "{fn: \"function_name\"} extra input";
let (input, f) = frame(input)?;
assert_eq!(" extra input", input);
assert_eq!(
Frame {
function: "function_name".into(),
file: None,
line: None,
},
f
);
let input = "{n: \"function_name\"} extra input";
let e = frame(input).unwrap_err();
match e {
Error {
kind: Kind::InvalidInput { found, .. },
..
} => {
assert_eq!(found, "n: \"");
}
_ => Err(e)?,
}
Ok(())
}
#[test]
fn start_test() -> eyre::Result<()> {
let input = "hi whatsup";
let input = start(input, "hi ")?;
assert_eq!("whatsup", input);
Ok(())
}
#[test]
fn delimited_test() -> eyre::Result<()> {
let input = "{this is delimited by {} some garbage} the remainder";
let (input, delimited_bit) = delimited(input, "{", "}")?;
assert_eq!("this is delimited by {} some garbage", delimited_bit);
assert_eq!(" the remainder", input);
Ok(())
}
#[test]
fn trailing_comma_test() -> eyre::Result<()> {
let input = ", hi whatsup";
let (input, had) = trailing_comma(input);
assert!(had);
let (_, had) = trailing_comma(input);
assert!(!had);
Ok(())
}
#[test]
fn header_test() -> eyre::Result<()> {
let input = header("Backtrace [")?;
assert!(input.is_empty());
match header("<disabled>") {
Err(Error {
kind: Kind::Disabled,
..
}) => (),
Err(e) => Err(e)?,
_ => unreachable!(),
}
match header("disabled backtrace") {
Err(Error {
kind: Kind::Disabled,
..
}) => (),
Err(e) => Err(e)?,
_ => unreachable!(),
}
match header("unsupported backtrace") {
Err(Error {
kind: Kind::Unsupported,
..
}) => (),
Err(e) => Err(e)?,
_ => unreachable!(),
}
match header("bunch of random garbage") {
Err(Error {
kind: Kind::UnexpectedInput(input),
..
}) => assert_eq!("bunch of random garbage", input),
Err(e) => Err(e)?,
_ => unreachable!(),
}
Ok(())
}
}
+181
View File
@@ -0,0 +1,181 @@
//! An error utility library for deserializing `std::backtrace::Backtrace`'s
//! based on its `Debug` format.
#![doc(html_root_url = "https://docs.rs/btparse/0.1.1")]
#![allow(clippy::try_err)]
use std::fmt;
mod deser;
/// A deserialized Backtrace.
///
/// # Example
///
/// ```rust
/// #![feature(backtrace)]
///
/// let backtrace = std::backtrace::Backtrace::force_capture();
/// let backtrace = btparse::deserialize(&backtrace).unwrap();
/// for frame in &backtrace.frames {
/// println!("{:?}", frame);
/// }
/// ```
#[derive(Debug)]
#[non_exhaustive]
pub struct Backtrace {
pub frames: Vec<Frame>,
}
/// A backtrace frame.
#[derive(Debug, PartialEq)]
pub struct Frame {
pub function: String,
pub file: Option<String>,
pub line: Option<usize>,
}
/// An error that prevented a backtrace from being deserialized.
#[derive(Debug)]
pub struct Error {
kind: Kind,
}
#[derive(Debug)]
enum Kind {
Disabled,
Empty,
Unsupported,
UnexpectedInput(String),
InvalidInput { expected: String, found: String },
LineParse(String, std::num::ParseIntError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "{}", self.kind)
}
}
impl fmt::Display for Kind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Disabled => write!(f, "backtrace capture disabled"),
Self::Empty => write!(f, "input is empty"),
Self::Unsupported => write!(f, "backtrace capture unsupported on this platform"),
Self::UnexpectedInput(input) => write!(f, "encountered unexpected input: {:?}", input),
Self::InvalidInput { expected, found } => write!(
f,
"invalid input, expected: {:?}, found: {:?}",
expected, found
),
Self::LineParse(input, _) => {
write!(f, "invalid line input for line number: {:?}", input)
}
}
}
}
impl std::error::Error for Error {}
impl From<Kind> for Error {
fn from(kind: Kind) -> Self {
Self { kind }
}
}
/// Deserialize a backtrace based on its debug format and return a parsed
/// representation containing a vector of frames.
pub fn deserialize(bt: &std::backtrace::Backtrace) -> Result<Backtrace, Error> {
let bt_str = format!("{:?}", bt);
deserialize_str(&bt_str)
}
fn deserialize_str(bt: &str) -> Result<Backtrace, Error> {
let mut frames = vec![];
let mut bt = deser::header(bt)?;
loop {
let (bt_next, frame) = deser::frame(bt)?;
bt = bt_next;
frames.push(frame);
let (bt_next, had_comma) = deser::trailing_comma(bt);
bt = bt_next;
if !had_comma {
break;
}
}
let bt = deser::close_bracket(bt)?;
if !bt.is_empty() {
Err(Kind::UnexpectedInput(bt.into()))?;
}
Ok(Backtrace { frames })
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn backtrace_deserialize_enabled() -> eyre::Result<()> {
let bt = std::backtrace::Backtrace::force_capture();
let bt_parsed = super::deserialize(&bt)?;
dbg!(bt_parsed);
Ok(())
}
#[test]
fn backtrace_deserialize_disabled() -> eyre::Result<()> {
let bt = std::backtrace::Backtrace::capture();
let bt_parsed = super::deserialize(&bt);
match bt_parsed {
Ok(_) => panic!("this should not parse"),
Err(Error {
kind: Kind::Disabled,
..
}) => (),
Err(e) => Err(e)?,
}
Ok(())
}
#[test]
fn deserialize_simple() -> eyre::Result<()> {
let backtrace = r#"Backtrace [{fn: "fn1", file: "fi"le1", line: 1}, {fn: "fn2", line: 2}, {fn: "fn3", file: "file3"}, {fn: "fn4"}]"#;
let expected = Backtrace {
frames: vec![
Frame {
function: "fn1".into(),
file: Some("fi\"le1".into()),
line: Some(1),
},
Frame {
function: "fn2".into(),
file: None,
line: Some(2),
},
Frame {
function: "fn3".into(),
file: Some("file3".into()),
line: None,
},
Frame {
function: "fn4".into(),
file: None,
line: None,
},
],
};
let bt_parsed = super::deserialize_str(backtrace)?;
dbg!(&bt_parsed);
assert_eq!(expected.frames, bt_parsed.frames);
Ok(())
}
}