src/lib.rs in faster_path-0.2.5 vs src/lib.rs in faster_path-0.2.6

- old
+ new

@@ -2,18 +2,21 @@ // // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. +#![feature(try_from)] + #[macro_use] extern crate ruru; #[macro_use] extern crate lazy_static; module!(FasterPath); +mod debug; mod helpers; mod pathname; mod basename; mod chop_basename; mod cleanpath_aggressive; @@ -23,11 +26,15 @@ mod pathname_sys; mod plus; mod prepend_prefix; pub mod rust_arch_bits; mod path_parsing; +mod relative_path_from; +use pathname::Pathname; +use pathname_sys::raise; + use ruru::{Module, Object, RString, Boolean, Array, AnyObject}; use pathname_sys::*; methods!( @@ -137,21 +144,25 @@ // fn r_root(){ pub_root(r_to_path()) } // fn pub_root(pth: RString){} // fn r_split_names(pth: RString){} - // fn r_relative_path_from(){} - // fn pub_relative_path_from(){} + fn pub_relative_path_from(itself: RString, base_directory: AnyObject) -> Pathname { + let to_string = |i: AnyObject| { RString::from(i.send("to_s", None).value()) }; + pathname::pn_relative_path_from(itself, base_directory.map(to_string)). + map_err(|e| raise(e) ).unwrap() + } + // fn pub_rmtree(pth: RString) -> NilClass { // pathname::pn_rmtree(pth) // } ); #[allow(non_snake_case)] #[no_mangle] -pub extern "C" fn Init_faster_pathname(){ +pub extern "C" fn Init_faster_pathname() { Module::from_existing("FasterPath").define(|itself| { itself.def_self("absolute?", pub_is_absolute); itself.def_self("add_trailing_separator", pub_add_trailing_separator); itself.def_self("del_trailing_separator", pub_del_trailing_separator); itself.def_self("cleanpath_aggressive", pub_cleanpath_aggressive); @@ -162,9 +173,10 @@ itself.def_self("has_trailing_separator?", pub_has_trailing_separator); //itself.def_self("join", pub_join); pathname_sys::define_singleton_method(itself.value(), "join", pub_join); itself.def_self("plus", pub_plus); itself.def_self("relative?", pub_is_relative); + itself.def_self("relative_path_from", pub_relative_path_from); itself.define_nested_class("Public", None); }); // For methods requiring addition Ruby-side behavior Module::from_existing("FasterPath").get_nested_class("Public").define(|itself| {