我对 rust 使用库的语法非常陌生。好吧,总的来说,大部分都是新的生锈。
我已经包含了一个未完成的库,并且似乎不起作用。该库称为“小时”,其中lib.rs
包含以下内容:
// #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Hours {
pub rules: Vec<types::RuleSequence>,
pub tz: Tz,
}
impl Hours {
pub fn from(s: &str, tz: Tz) -> Result<Self, String> {
//... abbreviated
}
pub fn at(self: &Self, dt: &DateTime<Tz>) -> types::Modifier {
//... abbreviated
}
}
它包含在Cargo.toml
:相关行:
edition = "2018"
[dependencies]
hours = "0.0.1"
我想知道是否可以包含和使用该from()
功能,到目前为止,我没有运气。这是我尝试过的:
use hours;
fn main() {
//... abbreviated
let hours = Hours::from(example_hrs, Amsterdam).unwrap();
}
给出编译错误:Hours::from(example_hrs, Amsterdam).unwrap(); ^^^^^ use of undeclared type or module
Hours``
use hours::Hours;
fn main() {
//... abbreviated
let hours = Hours::from(example_hrs, Amsterdam).unwrap();
}
给出编译错误:use hours::Hours; ^^^^^^^^^^^^ no ``Hours`` in the root
use hours;
fn main() {
//... abbreviated
let hours = hours::Hours::from(example_hrs, Amsterdam).unwrap();
}
给出编译错误:hours::Hours::from(example_hrs, Amsterdam).unwrap(); ^^^^^ could not find
Hours in
hours``
有没有办法包含和使用这个库?我是否需要更改库,或者我只是使用错误?