“expected struct Foo,found a different struct Foo”是什么意思?

4
我正在尝试构建一个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)?

一个人如何将body字符串转换为解析器期望的正确类型的tendril?这不是解析错误;解析器只关心语法。相反,这是一个语义错误。 - Francis Gagné
1个回答

6

这意味着您正在编译多个版本的tendril crate,并且不小心尝试混合它们。请确保任何依赖于tendril的东西都依赖于相同的tendril


2
@mpiccolo:是的,指的是Git版本与crates.io版本。请注意,[dependencies] tendril = "0.1"也可以使用,相当于[dependencies.tendril] version = 0.1 - Chris Morgan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接