我正在尝试编写一个组成两个函数的函数,初始设计非常简单,它是一个函数,它接受两个函数并返回一个组合函数,然后我可以用其他函数组合,(因为rust没有rest参数).但是我遇到了一个很长的硬墙,内置了令人沮丧的无用的编译器错误.
我的撰写功能:
fn compose<'a, A, B, C, G, F>(f: F, g: G) -> Box<Fn(A) -> C + 'a>
where
F: 'a + Fn(A) -> B + Sized,
G: 'a + Fn(B) -> C + Sized,
{
Box::new(move |x| g(f(x)))
}
Run Code Online (Sandbox Code Playgroud)
我想怎么用它:
fn main() {
let addAndMultiply = compose(|x| x * 2, |x| x + 2);
let divideAndSubtract = compose(|x| x / 2, |x| x - 2);
let finally = compose(*addAndMultiply, *divideAndSubtract);
println!("Result is {}", finally(10));
}
Run Code Online (Sandbox Code Playgroud)
rustc不喜欢那样,无论我尝试什么,特质界限永远不会满足.错误是:
error[E0277]: the size …Run Code Online (Sandbox Code Playgroud) 所以我基本上想要做的就是简单
class Something extends React.Component {
validateEmail () {
//code that validates email,innerHTML a div.status element if error occurs
this.removeStatus();//then remove status onkeydown of input element
}
removeStatus () {
//code that removes the status onkeydown of input element
}
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它不起作用.在我的JavaScript控制台(铬)我得到这个
login.js:132Uncaught TypeError: this.removeStatus is not a function
Run Code Online (Sandbox Code Playgroud)
编辑1:我已经添加了实际的代码,因为你可以看到我在构造函数中绑定了validateEmail
class Email extends React.Component {
constructor(props) {
super(props);
this.change = this.change.bind(this);
this.validateEmail = this.validateEmail.bind(this);
this.state = {
value : ''
}
}
removeStatus() {
$('input').on('keydown',function () {
$('.contextual-info').fadeOut();
});
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试为 swift 项目配置 clion,但它无法识别 swift 工具链路径。
$ which swift
产生输出
/usr/bin/swift/bin/swift
所以工具链就在那里,但 clion 只是不认识它
我该如何进行这项工作?
我有这段代码:
impl ArcService for (Box<MiddleWare<Request>>, Box<ArcService>) {
fn call(&self, req: Request, res: Response) -> Box<Future<Item = Response, Error = Error>> {
box self.0.call(req).and_then(move |req| self.1.call(req, res))
}
}
pub trait ArcService: Send + Sync {
fn call(&self, req: Request, res: Response) -> Box<Future<Item = Response, Error = Error>>;
}
pub trait MiddleWare<T>: Sync + Send {
fn call<'a>(&'a self, param: T) -> Box<Future<Item = T, Error = Error> + 'a>;
}
type MiddleWareFuture<'a, I> = Box<Future<Item = I, Error = …Run Code Online (Sandbox Code Playgroud) 在我的笔http://codepen.io/seunlanlege/pen/PbYNor?editors=0010#0
发生的事情非常简单.this.send()调用方法时 this.state.chat被发送到子组件<Messages /> which is then concatenated to thethis.state.messages`数组并呈现.
但问题是,渲染后更新1秒,this.state.sent这是一个支持<Messages />但消息组件不重新渲染.
请问如何强制它重新渲染?
class Messages extends React.Component{
constructor(props){
super(props);
}
render(){
return(
`<p id={this.props.key} className={this.props.style}>{this.props.msg}<span>{this.props.sent}</span></p>`);
}
}
class Chat extends React.Component {
constructor(props) {
super(props);
this.count = 0;
this.state = {chat :'',messages:[],sent:[]};
}
chatChange(event){
this.setState({chat : event.target.value});
}
send(e){
e.preventDefault();
let x = this.state.messages;
this.setState({messages:x.concat([<Messages style="me" msg={this.state.chat} key={this.state.chat} sent={(this.state.sent[this.count])?this.state.sent[this.count]:''} />])});
this.setState({chat:''});
setTimeout(()=>{
this.setState({sent:this.state.sent.concat(['sent'])});
this.count++;
},1000);
}
render () {
return( …Run Code Online (Sandbox Code Playgroud) ecmascript-6 ×2
javascript ×2
reactjs ×2
rust ×2
clion ×1
future ×1
lifetime ×1
swift ×1
swift3 ×1
ubuntu-16.04 ×1