fix: --no-default-features build

This commit is contained in:
Carson M.
2025-12-15 21:41:23 -06:00
parent 9a1d8bf9ef
commit 63b996529e
5 changed files with 40 additions and 41 deletions

View File

@@ -10,7 +10,7 @@ use std::{
str
};
use crate::{Error, ResultExt};
use crate::error::{Error, ResultExt};
fn parse_octal(bytes: &[u8]) -> io::Result<u64> {
let s = bytes.iter().take_while(|v| **v != 0).map(|v| *v as char).collect::<String>();

View File

@@ -12,7 +12,7 @@ use ureq::{
tls::{RootCerts, TlsConfig, TlsProvider}
};
use crate::{Error, log, vars};
use crate::{error::Error, log, vars};
mod extract;
mod resolve;

34
ort-sys/build/error.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::fmt;
#[derive(Debug)]
pub struct Error {
message: String
}
impl Error {
pub fn new(message: impl Into<String>) -> Self {
Self { message: message.into() }
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl<E: std::error::Error> From<E> for Error {
fn from(value: E) -> Self {
Self { message: value.to_string() }
}
}
pub trait ResultExt<T, E> {
fn with_context<S: fmt::Display, F: FnOnce() -> S>(self, ctx: F) -> Result<T, Error>;
}
impl<T, E: fmt::Display> ResultExt<T, E> for Result<T, E> {
fn with_context<S: fmt::Display, F: FnOnce() -> S>(self, ctx: F) -> Result<T, Error> {
self.map_err(|e| Error::new(format!("{}: {}", ctx(), e)))
}
}

View File

@@ -1,12 +1,10 @@
use std::{
env,
fmt::{self, Display},
path::PathBuf
};
use std::{env, path::PathBuf};
#[cfg(feature = "download-binaries")]
mod download;
mod dynamic_link;
#[cfg(feature = "download-binaries")]
mod error;
mod log;
#[cfg(feature = "pkg-config")]
mod pkg_config;
@@ -162,36 +160,3 @@ cargo::error= | The downloaded binaries are available to inspect at: {}",
println!("cargo:rustc-link-lib=static=onnxruntime");
}
}
#[derive(Debug)]
struct Error {
message: String
}
impl Error {
pub fn new(message: impl Into<String>) -> Self {
Self { message: message.into() }
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl<E: std::error::Error> From<E> for Error {
fn from(value: E) -> Self {
Self { message: value.to_string() }
}
}
trait ResultExt<T, E> {
fn with_context<S: fmt::Display, F: FnOnce() -> S>(self, ctx: F) -> Result<T, Error>;
}
impl<T, E: fmt::Display> ResultExt<T, E> for Result<T, E> {
fn with_context<S: fmt::Display, F: FnOnce() -> S>(self, ctx: F) -> Result<T, Error> {
self.map_err(|e| Error::new(format!("{}: {}", ctx(), e)))
}
}