我写了以下代码:
use std::io::{IoResult, Writer};
use std::io::stdio;
fn main() {
let h = |&: w: &mut Writer| -> IoResult<()> {
writeln!(w, "foo")
};
let _ = h.handle(&mut stdio::stdout());
}
trait Handler<W> where W: Writer {
fn handle(&self, &mut W) -> IoResult<()>;
}
impl<W, F> Handler<W> for F
where W: Writer, F: Fn(&mut W) -> IoResult<()> {
fn handle(&self, w: &mut W) -> IoResult<()> { (*self)(w) }
}
Run Code Online (Sandbox Code Playgroud)
然后rustc
在我的终端:
$ rustc writer_handler.rs
writer_handler.rs:8:15: 8:43 error: the trait `core::marker::Sized` is not …
Run Code Online (Sandbox Code Playgroud) 我试图在另一个自定义elemnent阴影根中访问我的自定义元素的内容.
index.html
只是有一个my-tag-wrapper
元素:
<!-- import HTMLs and init Polymer-->
...
<my-tag-wrapper></my-tag-wrapper>
...
Run Code Online (Sandbox Code Playgroud)
my_tag_wrapper.html
包含my-tag
带有paragraph元素的元素:
<polymer-element name="my-tag-wrapper" >
<template>
<my-tag>
<p>wrapped my-tag contents</p>
</my-tag>
</template>
<script type="application/dart" src="my_tag_wrapper.dart"></script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)
my_tag.html
只是渲染它的内容:
<polymer-element name="my-tag" >
<template>
<content></content>
</template>
<script type="application/dart" src="my_tag.dart"></script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)
my_tag.dart
将它的内容打印到控制台:
@CustomTag('my-tag')
class MyTagElement extends PolymerElement {
ParagraphElement get p => this.querySelector('p');
MyTagElement.created() : super.created() {
var pe = p;
var t = (pe == null) ? null : pe.text;
print('my-tag p: ${t}');
print('my-tag outerHtml: …
Run Code Online (Sandbox Code Playgroud)