Skip to content

Commit

Permalink
Try #201:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Mar 23, 2023
2 parents eb30a8b + 86f09f5 commit 03aa3a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions godot-core/src/builtin/node_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

use std::fmt;
use std::str::FromStr;

use crate::builtin::GodotString;
use godot_ffi as sys;
Expand Down Expand Up @@ -60,6 +61,15 @@ impl From<&str> for NodePath {
}
}

// TODO: Check if it's required to implement Err
impl FromStr for NodePath {
type Err = ();

fn from_str(path: &str) -> Result<Self, ()> {
Ok(Self::from(&GodotString::from(path)))
}
}

impl fmt::Display for NodePath {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let string = GodotString::from(self);
Expand Down
11 changes: 11 additions & 0 deletions itest/rust/src/node_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use godot::builtin::{NodePath, Variant};
use godot::engine::{global, node, Node, Node3D, NodeExt, PackedScene, SceneTree};
use godot::obj::Share;

use std::str::FromStr;

#[itest]
fn node_get_node() {
let mut child = Node3D::new_alloc();
Expand Down Expand Up @@ -54,6 +56,15 @@ fn node_get_node_fail() {
child.free();
}

#[itest]
fn node_path_from_str(ctx: &TestContext) {
let child = ctx.scene_tree.share();
assert_eq!(
child.get_path().to_string(),
NodePath::from_str("/root/TestRunner").unwrap().to_string()
);
}

#[itest(skip)]
fn node_scene_tree() {
let mut child = Node::new_alloc();
Expand Down

0 comments on commit 03aa3a8

Please sign in to comment.