Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/alpha' into improve
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvict committed Sep 5, 2022
2 parents 89122d7 + 06bd606 commit 8e14182
Show file tree
Hide file tree
Showing 36 changed files with 747 additions and 329 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
]
exclude = [
"*",
"module/move/_video_experiment",
# "module/rust/-*",
# "sample/rust/-*",
# "module/rust/_*",
Expand Down
115 changes: 115 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# abc def
# === common
#

# Comma
comma := ,

# Checks two given strings for equality.
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
$(findstring $(2),$(1))),1)

#
# === Parameters
#

VERSION ?= $(strip $(shell grep -m1 'version = "' Cargo.toml | cut -d '"' -f2))

#
# === Git
#

# Sync local repostiry.
#
# Usage :
# make git.sync [message='description of changes']

git.sync :
git add --all && git commit -am $(message) && git pull

sync : git.sync

#
# === General commands
#

# Generate crates documentation from Rust sources.
#
# Usage :
# make doc [private=(yes|no)] [open=(yes|no)] [clean=(no|yes)]

doc :
ifeq ($(clean),yes)
@rm -rf target/doc/
endif
cargo doc --all-features --package editor_tui \
$(if $(call eq,$(private),no),,--document-private-items) \
$(if $(call eq,$(open),no),,--open)

# Format Rust sources with rustfmt.
#
# Usage :
# make fmt [check=(no|yes)]

fmt :
{ find -L module -name *.rs -print0 ; } | xargs -0 rustfmt +nightly $(if $(call eq,$(check),yes),-- --check,)

# cargo +nightly fmt --all $(if $(call eq,$(check),yes),-- --check,)

# Lint Rust sources with Clippy.
#
# Usage :
# make lint

lint :
cargo clippy --all-features -- -D warnings

# Format nad lint Rust sources.
#
# Usage :
# make lint

normalize : fmt lint

# Run project Rust sources with Cargo.
#
# Usage :
# make up

up :
cargo up

# Run project Rust sources with Cargo.
#
# Usage :
# make clean

clean :
cargo clean && rm -rf Cargo.lock && cargo cache -a && cargo update

# Run Rust tests of project.
#
# Usage :
# make test

test :
cargo test --all-features

# Run format link test and tests.
#
# Usage :
# make all

all : fmt lint test
#
# === .PHONY section
#

.PHONY : \
all \
docs \
fmt \
lint \
test \
up \
doc
1 change: 1 addition & 0 deletions module/move/_video_experiment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ path = "rust/test/video/video_experiment_tests.rs"

[dependencies]
wtools = { version = "~0.2", path = "../../rust/wtools" }
wmath = "~0.3"
gif = "~0.11"
apng = "~0.2.0"
png = "~0.16.3"
Expand Down
190 changes: 126 additions & 64 deletions rust/impl/ca/ca/command.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#![ allow( missing_docs ) ]
/* does not work locally */
/* rrr : for Dmytro : remove when former will be extended */

pub( crate ) mod private
{
use std::collections::HashMap;
use std::rc::Rc;
use core::fmt;
use wtools::error::{ Result, BasicError };
use crate::protected::*;
// use crate::
// {
// field_str,
// field_map_str_str,
// field_map_str_vec_str,
// field_routine,
// };
use std::
{
collections::HashMap,
rc::Rc,
fmt,
};
use wtools::
{
error::{ Result, BasicError },
meta::Former,
};

///
/// Handle for command routine.
Expand Down Expand Up @@ -54,7 +57,7 @@ pub( crate ) mod private
}
}

impl From<&'static dyn Fn( &crate::instruction::Instruction ) -> Result< () >> for OnCommand
impl From< &'static dyn Fn( &crate::instruction::Instruction ) -> Result< () > > for OnCommand
{
fn from( src : &'static dyn Fn( &crate::instruction::Instruction ) -> Result< () > ) -> Self
{
Expand All @@ -76,7 +79,7 @@ pub( crate ) mod private

impl fmt::Debug for OnCommand
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result
{
match self
{
Expand All @@ -86,27 +89,121 @@ pub( crate ) mod private
}
}

impl PartialEq for OnCommand
{
fn eq( &self, other : &Self ) -> bool
{
match self
{
OnCommand( Option::None ) =>
{
if other.0.is_none()
{
return true;
}
false
},
}
}

///
/// Command descriptor.
///
#[derive( Default, Debug, Clone )]
#[ derive( Debug, Clone ) ]
#[ derive( Former ) ]
pub struct Command
{
/// Command common hint.
// /// Command common hint.
pub hint : String,
/// Command full hint.
// /// Command full hint.
pub long_hint : String,
/// Phrase descriptor for command.
// /// Phrase descriptor for command.
pub phrase : String,
/// Command subject hint.
// /// Command subject hint.
pub subject_hint : String,
/// Hints for command options.
// /// Hints for command options.
pub properties_hints : HashMap< String, String >,
/// Map of aliases.
// /// Map of aliases.
pub properties_aliases : HashMap< String, Vec< String > >,
/// Command routine.
pub routine : OnCommand,
// /// Command routine.
/* rrr : for Dmytro : use name `routine` when former will be extended */
pub _routine : OnCommand,
}

impl CommandFormer
{
/// Alias for routine `routine`.
pub fn routine( mut self, src : &'static dyn Fn( &crate::instruction::Instruction ) -> Result< () > ) -> Self
{
self._routine = ::core::option::Option::Some( OnCommand( Some( Rc::new( src ) ) ) );
self
}

/// Alias for routine `hint`.
pub fn h( mut self, help : impl AsRef< str > ) -> Self
{
self.hint = Some( help.as_ref().into() );
self
}

/// Alias for routine `long_hint`.
pub fn lh( mut self, help : impl AsRef< str > ) -> Self
{
self.long_hint = Some( help.as_ref().into() );
self
}

/// Alias for routine `routine`.
pub fn ro( mut self, src : &'static dyn Fn( &crate::instruction::Instruction ) -> Result< () > ) -> Self
{
self._routine = ::core::option::Option::Some( OnCommand( Some( Rc::new( src ) ) ) );
self
}

/// Setter for separate properties.
pub fn property_hint< S : AsRef< str > >( mut self, key : S, hint : S ) -> Self
{
let key = key.as_ref();
let hint = hint.as_ref();

if self.properties_hints.is_none()
{
self.properties_hints = Some( HashMap::from([ ( key.into(), hint.into() ) ]) );
}
else
{
let hmap = self.properties_hints.as_mut().unwrap();
hmap.insert( key.into(), hint.into() );
}
self
}

/// Setter for separate properties aliases.
pub fn property_alias< S : AsRef< str > >( mut self, key : S, alias : S ) -> Self
{
let key = key.as_ref();
let alias = alias.as_ref();

if self.properties_aliases.is_none()
{
self.properties_aliases = Some( HashMap::from([ ( key.into(), vec![ alias.into() ] ) ]) );
}
else
{
let hmap = self.properties_aliases.as_mut().unwrap();
if hmap.get( key ).is_some()
{
let vec_aliases = hmap.get_mut( key ).unwrap();
vec_aliases.push( alias.into() );
}
else
{
hmap.insert( key.into(), vec![ alias.into() ] );
}
}
self
}
}

impl PartialEq for Command
Expand All @@ -117,6 +214,9 @@ pub( crate ) mod private
self.hint == other.hint
&& self.long_hint == other.long_hint
&& self.subject_hint == other.subject_hint
&& self.properties_hints == other.properties_hints
&& self.properties_aliases == other.properties_aliases
/* rrr : for Dmytro : try to extend using option OnCommand */
}
}

Expand Down Expand Up @@ -151,52 +251,14 @@ pub( crate ) mod private
return Err( BasicError::new( "Unknown option." ) );
}
}
if self.routine.callable()
if self._routine.callable()
{
return self.routine.perform( instruction );
return self._routine.perform( instruction );
}

Ok( () )
}
}

///
/// Options for command.
///
#[derive( Debug, Clone, Default )]
pub struct CommandOptions
{
ins : Command,
}

//

// ro : null,
// h : null,
// lh : null,

impl CommandOptions
{
field_str!{ hint }
field_str!{ hint, h }
field_str!{ long_hint }
field_str!{ long_hint, lh }
field_str!{ phrase }
field_str!{ subject_hint }
field_str!{ subject_hint, sh }
field_map_str_str!{ properties_hints, property_hint }
field_map_str_vec_str!{ properties_aliases, property_alias }
field_routine!{ routine }
field_routine!{ routine, ro }

/// Command former.
pub fn form( &self ) -> Command
{
self.ins.clone()
}

}
}

//
Expand All @@ -205,5 +267,5 @@ crate::mod_interface!
{
prelude use OnCommand;
prelude use Command;
prelude use CommandOptions;
prelude use CommandFormer;
}
Loading

0 comments on commit 8e14182

Please sign in to comment.