pub fn register<T: FnRegister>(&mut self, f: T, name: &str) {
f.register(self, name);
}
Error: the trait rhai::fn_register::FnRegister
is not implemented for the type fn(i32) -> i32 {add}
[E0277]
//use std::fmt; | |
#include <iostream> | |
// | |
//struct Foo { | |
// x: i32 | |
//} | |
struct Foo { |
fn simple_fn(x: i32) -> i32 { | |
x + 100 | |
} | |
trait FooFn { | |
fn foo(&self); | |
} | |
impl FooFn for Fn(i32)->i32 { | |
fn foo(&self) { |
fn parse_if<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Stmt, ParseError> { | |
Ok(Stmt::Expr(Node::IntConst(3))) | |
} | |
fn parse_expr_stmt<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Stmt, ParseError> { | |
Ok(Stmt::Expr(Node::IntConst(4))) | |
} | |
fn parse_stmt<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Stmt, ParseError> { | |
let mut parser = match input.peek() { |
use std::any::Any; | |
#[derive(Debug)] | |
struct Engine { | |
x: i32 | |
} | |
trait FnRegisterTest { | |
fn register(self, engine: &mut Engine, name: &str); | |
} |
use std::any::Any; | |
#[derive(Debug)] | |
struct Engine { | |
x: i32 | |
} | |
trait FnRegister1V { | |
fn register<T: Fn(U)->V, U, V>(&mut self, name: &str, f: T); | |
} |
use std::any::Any; | |
#[derive(Debug)] | |
struct Engine { | |
x: i32 | |
} | |
trait FnRegister<RetVal, Args> { | |
fn register<T: Fn(Args)->RetVal>(&mut self, name: &str, f: T); | |
} |
trait FnRegister<A, RetVal, Args> { | |
fn register(&mut self, name: &str, f: A); | |
} | |
impl<A, RetVal, Arg1> FnRegister<A, RetVal, (Arg1,)> for Bob | |
where A: 'static + Fn(Arg1)->RetVal | |
{ | |
fn register(self, name: &str, fun: fn(Arg1)->RetVal) { | |
println!("Fn(T)->U"); | |
} |
I tried this successfully with Emacs 25. It may also work with earlier versions.
GUI support in Rust could be built on a central crate that has a common set of GUI components (button, menubar, dropdown, etc). It would also have first-party connectors to the GUI that's "native" for a given platform.
Wrapping native GUI by default means that each app will feel natural for the given platform, including not only the look of the widgets, but also tricky elements like text input would work just as they with native inputs. The native platforms already put a ton of work into getting this right, let's just leverage it.
Because of the difference in platforms, what if the GUI crate didn't take (x,y) coordinates, but instead used a more constraint-based layout mechanism. This may help cut down on the fiddling you have to do when getting it to work well between platforms.
Rust has a very "fluent" style, and it's not uncommon to see people use this to simulate optional named arguments. I think we could use this to give the library a bit of a Rust feel.
Simple example: