我有以下类型:
type RangeFn = fn(&Value, &Value) -> bool;
现在我想把它与这个struct
放在一起:
#[derive(Debug)]
struct Range {
fun: RangeFn,
}
但是,如果我有一个以struct
作为参数的RangeFn
,那么我似乎无法从Debug
派生它。如何使RangeFn
与Debug
特性兼容?
答案 0 :(得分:6)
You can't implement (or derive) a trait you don't own on a type you don't own.
但是,这不是您想要的。您想要的是为// Scroll.js (https://css-tricks.com/snippets/jquery/smooth-
scrolling/#comment-1635851)
/*
* Scroll.js:
* 1. added -100 after the .top property which reflects the navigation height.
*/
$(document).ready(function(){
// Add smooth scrolling to all links
$('a').on('click', function(e) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
e.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top-100 // /* [1] */
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
实现Debug
,但是您不能通过派生来实现,因为Range
没有实现fn
。
确实,派生Debug
还要求所有字段也都是Debug
。然后,您将不得不自己实施Debug
;毕竟,这只是正常现象:
Debug