Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 23 additions & 23 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
max_width = 80
max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
newline_style = "Unix"
indent_style = "Block"
use_small_heuristics = "Default"
fn_call_width = 60
attr_fn_like_width = 70
struct_lit_width = 18
struct_variant_width = 35
array_width = 60
chain_width = 60
single_line_if_else_max_width = 50
wrap_comments = false
format_code_in_doc_comments = false
comment_width = 80
use_small_heuristics = "Max"
fn_call_width = 100
attr_fn_like_width = 100
struct_lit_width = 100
struct_variant_width = 100
array_width = 100
chain_width = 100
single_line_if_else_max_width = 100
wrap_comments = true
format_code_in_doc_comments = true
comment_width = 100
normalize_comments = false
normalize_doc_attributes = false
license_template_path = ""
Expand All @@ -23,10 +23,10 @@ format_macro_bodies = true
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
where_single_line = true
imports_indent = "Block"
imports_layout = "Mixed"
imports_granularity = "Preserve"
imports_granularity = "Item"
group_imports = "Preserve"
reorder_imports = true
reorder_modules = true
Expand All @@ -38,26 +38,26 @@ spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = true
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
overflow_delimited_expr = true
struct_field_align_threshold = 20
enum_discrim_align_threshold = 20
match_arm_blocks = false
match_arm_leading_pipes = "Never"
force_multiline_blocks = false
fn_args_layout = "Tall"
brace_style = "SameLineWhere"
brace_style = "PreferSameLine"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_upper_bound = 3
blank_lines_lower_bound = 0
edition = "2015"
edition = "2018"
version = "One"
inline_attribute_width = 0
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
use_field_init_shorthand = true
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
Expand Down
29 changes: 15 additions & 14 deletions src/rust/build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
#![feature(trait_alias)]

use std::path;
use std::io::ErrorKind;
use std::fmt::Display;
use std::io::ErrorKind;
use std::path;

/// Types that can yield a reference to std::path::Path.
pub trait PathRef = AsRef<path::Path>;

/// A structure describing a concrete release package on GitHub.
pub struct GithubRelease<T> {
pub project_url : T,
pub version : T,
pub filename : T,
pub project_url: T,
pub version: T,
pub filename: T,
}

impl<T:AsRef<str>+Display> GithubRelease<T> {
impl<T: AsRef<str> + Display> GithubRelease<T> {
/// Download the release package from GitHub if the target file was missing. Returns true if
/// the file was downloaded or false if it already existed.
///
/// The project_url should be a project's main page on GitHub.
pub fn download(&self, destination_dir:&path::Path) {
let url = format!("{}/releases/download/{}/{}",self.project_url,self.version,self.filename);
pub fn download(&self, destination_dir: &path::Path) {
let url =
format!("{}/releases/download/{}/{}", self.project_url, self.version, self.filename);
let destination_file = destination_dir.join(self.filename.as_ref());
Self::remove_old_file(&destination_file);
let mut resp = reqwest::blocking::get(&url).expect("Download failed.");
let mut out = std::fs::File::create(destination_file).expect("Failed to create file.");
let mut out = std::fs::File::create(destination_file).expect("Failed to create file.");
std::io::copy(&mut resp, &mut out).expect("Failed to copy file content.");
}

fn remove_old_file(file:&path::Path) {
let result = std::fs::remove_file(&file);
let error = result.err();
fn remove_old_file(file: &path::Path) {
let result = std::fs::remove_file(&file);
let error = result.err();
let fatal_error = error.filter(|err| err.kind() != ErrorKind::NotFound);
assert!(fatal_error.is_none());
}
Expand All @@ -48,10 +49,10 @@ pub fn absolute_path(path: impl PathRef) -> std::io::Result<path::PathBuf> {
}

/// Get the environment variable or panic if not available.
pub fn env_var_or_panic(var_name:&str) -> String {
pub fn env_var_or_panic(var_name: &str) -> String {
match std::env::var(var_name) {
Ok(var) => var,
Err(e) => panic!("Failed to read environment variable {}: {}.", var_name, e),
Err(e) => panic!("Failed to read environment variable {}: {}.", var_name, e),
}
}

Expand Down
38 changes: 21 additions & 17 deletions src/rust/ensogl/build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use std::{path, env};
use std::env;
use std::path;

/// A module with functions generating huge chunk of texts for text component benchmarks.
mod huge_text_generator {
use std::collections::hash_map::DefaultHasher;
use std::fs::File;
use std::hash::{Hash,Hasher};
use std::hash::Hash;
use std::hash::Hasher;
use std::io::Write;
use std::path::Path;

const MANY : usize = 100000;
const NOT_SO_MANY : usize = 100;
const MANY: usize = 100000;
const NOT_SO_MANY: usize = 100;

/// Create a file with many lines.
pub fn make_long_text_file(name:&Path) {
pub fn make_long_text_file(name: &Path) {
let mut file = File::create(name).unwrap();
for i in (1..MANY).rev() {
write_verse(&mut file, i);
Expand All @@ -21,40 +23,42 @@ mod huge_text_generator {
}

/// Create a file with not so many long lines
pub fn make_wide_text_file(name:&Path) {
let mut file = File::create(name).unwrap();
let verses_in_line = MANY/NOT_SO_MANY;
pub fn make_wide_text_file(name: &Path) {
let mut file = File::create(name).unwrap();
let verses_in_line = MANY / NOT_SO_MANY;
for i in (1..MANY).rev() {
write_verse(&mut file, i);
if i % verses_in_line == 0 {
let line_index = i / verses_in_line;
let offset = hash_from(line_index) % 32;
let prefix = (0..offset).map(|_| '|').collect::<String>();
let offset = hash_from(line_index) % 32;
let prefix = (0..offset).map(|_| '|').collect::<String>();
writeln!(file).unwrap();
write!(file,"{}",prefix).unwrap();
write!(file, "{}", prefix).unwrap();
}
}
}

fn hash_from(i:usize) -> u64 {
fn hash_from(i: usize) -> u64 {
let mut hasher = DefaultHasher::new();
i.hash(&mut hasher);
hasher.finish()
}

fn write_verse(file:&mut File, i:usize) {
write!(file,
fn write_verse(file: &mut File, i: usize) {
write!(
file,
"{i} bottles of beer on the wall, {i} bottles of beer.\
Take one down and pass it around, {j} bottles of beer on the wall. ",
i = i,
j = i-1
).unwrap();
j = i - 1
)
.unwrap();
}
}


fn main() {
let out = env::var("OUT_DIR").unwrap();
let out = env::var("OUT_DIR").unwrap();
let out_dir = path::Path::new(&out);
huge_text_generator::make_long_text_file(out_dir.join("long.txt").as_path());
huge_text_generator::make_wide_text_file(out_dir.join("wide.txt").as_path());
Expand Down
5 changes: 2 additions & 3 deletions src/rust/ensogl/example/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use crate::prelude::*;

use ensogl_core::system::web;
use ensogl_core::application::Application;
use ensogl_core::system::web;
use ensogl_core::DEPRECATED_Animation;
use ensogl_text_msdf_sys::run_once_initialized;
use logger::TraceLogger as Logger;
Expand Down Expand Up @@ -34,8 +34,7 @@ pub fn entry_point_animation() {
// ========================

fn init() {

let logger : Logger = Logger::new("AnimationTest");
let logger: Logger = Logger::new("AnimationTest");
let network = enso_frp::Network::new("test");
let animation = DEPRECATED_Animation::<f32>::new(&network);
animation.set_target_value(-259_830.0);
Expand Down
Loading