Comments (5)
You can convert either a Value
or an Array
into a Vec<T>
using the TryFrom
trait (Specifically this and this impl.)
This should work:
let array: Vec< String > = js! { return ["foo", "bar"]; }.try_into().unwrap();
You can't currently access a JavaScript array in Rust without converting it to a vector first.
from stdweb.
Thanks for the quick answer!
I wasn't aware of the .try_into()
function! Looks good.
The above error seems to persist though:
error[E0277]: the trait bound `std::vec::Vec<std::string::String>: std::convert::From<stdweb::Value>` is not satisfied
--> src/main.rs:25:63
|
25 | let array: Vec< String > = js! { return ["foo", "bar"]; }.try_into().unwrap();
| ^^^^^^^^ the trait `std::convert::From<stdweb::Value>` is not implemented for `std::vec::Vec<std::string::String>`
|
= help: the following implementations were found:
<std::vec::Vec<stdweb::Value> as std::convert::From<&'a stdweb::Array>>
<std::vec::Vec<u8> as std::convert::From<&'a stdweb::web::TypedArray<u8>>>
<std::vec::Vec<stdweb::Value> as std::convert::From<&'a mut stdweb::Array>>
<std::vec::Vec<stdweb::Value> as std::convert::From<stdweb::Array>>
and 10 others
= note: required because of the requirements on the impl of `std::convert::TryFrom<stdweb::Value>` for `std::vec::Vec<std::string::String>`
= note: required because of the requirements on the impl of `std::convert::TryInto<std::vec::Vec<std::string::String>>` for `stdweb::Value`
Seems like I am missing a piece of the puzzle there ...
from stdweb.
You're using the wrong TryFrom
. (:
The std::convert::TryFrom
is still unstable, so we have our own in stdweb::unstable::TryFrom
/stdweb::unstable::TryInto
.
from stdweb.
That did the trick!
Thanks for your swift help 😃
This might as well be the next big thing for Rust ;)
Props to you good sir and this project! Keep up the amazing work!
from stdweb.
No problem; thanks. (:
from stdweb.
Related Issues (20)
- Unnecessary recompilation when switching between cargo check and cargo web deploy
- InsertNodeError is private HOT 1
- add_event_listener doesn't support useCapture option
- Add HtmlButtonElement to html_elements mod HOT 3
- How to obtain XmlHttpRequest response outside clousure. HOT 1
- unexpected char in asm const signature 101 HOT 4
- Feature request: Element.{clientWidth,clientHeight}
- Feature Idea: Implementation of CustomEvent?
- Error loading wasm-bindgen-minimal example HOT 1
- Maintenance status? HOT 6
- If I use 'rand' library anywhere before rendering, it renders nothing on the website HOT 2
- please update sha1 to sha-1
- Undefined behavior when creating SerializedValue HOT 4
- Should initialize's panic hook work with a `&str` payload? HOT 1
- linking with `cc` failed: exit code: 1
- Panic on Firefox with Trunk
- `js` macro doesn't work with `wasm-bindgen --target no-modules`
- `RuntimeError: unreachable` when loading `wasm-bindgen-minimal` example in the browser ...
- console! can't work on web front-end page
- Not compiling with newest version of dependencies HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stdweb.