@@ -5,7 +5,6 @@ use crate::bindings as ll_bindings;
55use crate :: error:: TskitError ;
66use crate :: types:: Bookmark ;
77use crate :: IndividualTableSortOptions ;
8- use crate :: NodeDefaults ;
98use crate :: Position ;
109use crate :: SimplificationOptions ;
1110use crate :: TableClearOptions ;
@@ -411,22 +410,43 @@ impl TableCollection {
411410 /// ```
412411 /// # let mut tables = tskit::TableCollection::new(1.).unwrap();
413412 /// let node_defaults = tskit::NodeDefaults::default();
414- /// let rv = tables.add_node_with_defaults(1.0, node_defaults).unwrap();
413+ /// let rv = tables.add_node_with_defaults(1.0, & node_defaults).unwrap();
415414 /// assert_eq!(rv, 0);
416- /// let rv = tables.add_node_with_defaults(2.0, node_defaults).unwrap();
415+ /// let rv = tables.add_node_with_defaults(2.0, & node_defaults).unwrap();
417416 /// assert_eq!(rv, 1);
418417 /// ```
419- pub fn add_node_with_defaults < T : Into < crate :: Time > + Copy > (
418+ pub fn add_node_with_defaults <
419+ T : Into < crate :: Time > ,
420+ D : crate :: node_table:: DefaultNodeData ,
421+ > (
420422 & mut self ,
421423 time : T ,
422- defaults : NodeDefaults ,
424+ defaults : & D ,
423425 ) -> Result < NodeId , TskitError > {
424- self . add_node (
425- defaults. flags ,
426- time,
427- defaults. population ,
428- defaults. individual ,
429- )
426+ let md = defaults. metadata ( ) ?;
427+ let ( ptr, mdlen) = match & md {
428+ Some ( value) => (
429+ value. as_ptr ( ) . cast :: < i8 > ( ) ,
430+ crate :: SizeType :: try_from ( value. len ( ) ) ?,
431+ ) ,
432+ None => ( std:: ptr:: null ( ) , 0 . into ( ) ) ,
433+ } ;
434+ let flags: ll_bindings:: tsk_flags_t = defaults. flags ( ) . bits ( ) ;
435+ let population: ll_bindings:: tsk_id_t = defaults. population ( ) . into ( ) ;
436+ let individual: ll_bindings:: tsk_id_t = defaults. individual ( ) . into ( ) ;
437+ let time: f64 = time. into ( ) . into ( ) ;
438+ let rv = unsafe {
439+ ll_bindings:: tsk_node_table_add_row (
440+ & mut ( * self . as_mut_ptr ( ) ) . nodes ,
441+ flags,
442+ time,
443+ population,
444+ individual,
445+ ptr,
446+ mdlen. into ( ) ,
447+ )
448+ } ;
449+ handle_tsk_return_value ! ( rv, rv. into( ) )
430450 }
431451
432452 node_table_add_row_with_metadata ! (
0 commit comments