/// Performs transformations on a function to make it mockable fn mockable_fn(mut item_fn: ItemFn) -> ItemFn {
demutify(&mut item_fn.sig.inputs);
deimplify(&mut item_fn.sig.output);
item_fn
}
/// Performs transformations on an Item to make it mockable fn mockable_item(item: Item) -> Item { match item {
Item::Fn(item_fn) => Item::Fn(mockable_fn(item_fn)),
x => x
}
}
/// An item that's ready to be mocked. /// /// It should be functionally identical or near-identical to the original item, /// but with minor alterations that make it suitable for mocking, such as /// altered lifetimes. pub(crate) enum MockableItem {
Module(MockableModule), Struct(MockableStruct)
}
impl From<(Attrs, Item)> for MockableItem { fn from((attrs, item): (Attrs, Item)) -> MockableItem { match item {
Item::Impl(item_impl) =>
MockableItem::Struct(MockableStruct::from(item_impl)),
Item::Mod(item_mod) =>
MockableItem::Module(MockableModule::from(item_mod)),
Item::Trait(trait_) =>
MockableItem::Struct(MockableStruct::from((attrs, trait_))),
_ => panic!("automock does not support this item type")
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.