gpt4 book ai didi

rust - "expected struct Foo, found a different struct Foo"是什么意思?

转载 作者:行者123 更新时间:2023-11-29 07:57:47 25 4
gpt4 key购买 nike

我正在尝试构建一个 HTML 网络抓取工具,但遇到了一个我无法克服的障碍。

#![feature(libc)]
#![feature(rustc_private)]
extern crate libc;

extern crate url;
extern crate hyper;
extern crate html5ever;
extern crate serialize;
extern crate html5ever_dom_sink;

#[macro_use]
extern crate tendril;

use tendril::{StrTendril, SliceExt};
use std::ffi::{CStr,CString};
use tendril::{ByteTendril, ReadExt};
use html5ever::{parse, one_input};
use html5ever_dom_sink::common::{Document, Doctype, Text, Comment, Element};
use html5ever_dom_sink::rcdom::{RcDom, Handle};

use hyper::Client;
use hyper::header::Connection;
use std::io::Read;

fn get_page(url: &str) -> String {
let mut client = Client::new();
let mut res = client.get(url)
// set a header
.header(Connection::close())
// let 'er go!
.send().unwrap();

let mut body = String::new();
res.read_to_string(&mut body).unwrap();

body
}

#[no_mangle]
pub extern fn parse_page(url: *const libc::c_char) {
let url_cstr = unsafe { CStr::from_ptr(url) }; // &std::ffi::c_str::CStr
let url_and_str = url_cstr.to_str().unwrap(); // &str

let body = get_page(url_and_str);

let body_tendril = body.to_tendril();
let body_tendril = body_tendril.try_reinterpret().unwrap();

let dom: RcDom = parse(one_input(body_tendril), Default::default());


// let c_body = CString::new(body).unwrap(); // std::ffi::c_str::CString

// c_body.into_ptr()
}

当我使用 cargo 构建这个库时,出现错误:

error: type mismatch resolving `<core::option::IntoIter<tendril::tendril::Tendril<_>> as core::iter::Iterator>::Item == tendril::tendril::Tendril<tendril::fmt::UTF8>`:
expected struct `tendril::tendril::Tendril`,
found a different struct `tendril::tendril::Tendril`

如何将正文字符串转换为解析所期望的正确类型的卷须?

最佳答案

这表明您已经编译了多个版本的 tendril crate,并且您正试图不小心混合使用它们。确保任何依赖于 tendril 的事物都依赖于相同的 tendril

关于rust - "expected struct Foo, found a different struct Foo"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31130408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com