Skip to content

Commit

Permalink
1. attempting minor changes to readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
denisandroid committed May 16, 2024
1 parent cfe2738 commit 79e4cff
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*.rs]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
indent_style = tab
indent_size = 5
max_line_length = 80
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</br></br>
</div>

## Description:
## Description

Our community is dedicated to providing a respectful and inclusive environment for everyone, regardless of gender, age, sexual orientation, disability, physical appearance, body size, race, nationality, or religion.

Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
<a href="https://github.com/clucompany">
<img src="https://github.com/UlinProject/img/blob/main/short_32/clulab.png?raw=true" alt="clulab"/>
</a>

[![CI](https://github.com/clucompany/cluCStr/actions/workflows/CI.yml/badge.svg?event=push)](https://github.com/clucompany/cluCStr/actions/workflows/CI.yml)

[![CI](https://github.com/clucompany/cluCStr/actions/workflows/CI.yml/badge.svg?event=push)](https://github.com/clucompany/cluCStr/actions/workflows/CI.yml)

</div>
</div>

## Note:
## Note

<b>You can use `c"wow"` since Rust 1.77.0 instead of `cstr!("wow")` from this crate. This new feature provides more concise code and faster compilation. If you are using an older Rust API (like 1.66), this crate will still be relevant for some time.</b>

## Usage:
## Usage

Add this to your Cargo.toml:

Expand All @@ -42,45 +41,49 @@ clucstr = "1.2.0"
```

and this to your source code:

```rust
use cluCStr::cstr;
use core::ffi::CStr;
```

## Example:
## Example

```rust
use cluCStr::cstr;
use core::ffi::CStr;

fn main() {
let cstr = cstr!(b"How are you?");
assert_eq!(cstr.to_bytes_with_nul(), b"How are you?\0");
let cstr = cstr!(b"How are you?");
assert_eq!(cstr.to_bytes_with_nul(), b"How are you?\0");
}
```

<a href="./examples">
See all
</a>

## License:
## License

This project has a single license (LICENSE-APACHE-2.0).

<div align="left">
<a href="https://github.com/denisandroid">
<img align="left" src="https://github.com/UlinProject/img/blob/main/block_220_100/uproject.png?raw=true" alt="uproject"/>
</a>
<b>&nbsp;Copyright (c) 2019-2024 #UlinProject</b>

<b>&nbsp;(Denis Kotlyarov).</b>
</br></br></br>
</div>

### Apache License:
### Apache License

<div align="left">
<a href="./LICENSE">
<img align="left" src="https://github.com/UlinProject/img/blob/main/block_220_100/apache2.png?raw=true" alt="apache2"/>

</a>
<b>&nbsp;Licensed under the Apache License, Version 2.0.</b>
</br></br></br></br>
Expand Down
28 changes: 14 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
/*!
Safe and efficient creation of "CStr" with zero-byte checking and support for concatenating multiple values.
## Note:
## Note
You can use `c"wow"` since Rust 1.77.0 instead of `cstr!("wow")` from this crate. This new feature provides more concise code and faster compilation. If you are using an older Rust API (like 1.66), this crate will still be relevant for some time.
## Example:
## Example
```rust
use cluCStr::cstr;
use core::ffi::CStr;
Expand All @@ -54,7 +54,7 @@ use quote::quote;
use proc_macro::TokenStream;
use proc_macro2::{TokenTree as TokenTree2, Literal, Span};

/// Returns tokens that generate a compilation error with the given message
/// Returns tokens that generate a compilation error with the given message
/// in the specified source code range.
#[inline]
fn __make_pm_compile_error(span: Span, message: &str) -> TokenStream {
Expand All @@ -64,15 +64,15 @@ fn __make_pm_compile_error(span: Span, message: &str) -> TokenStream {
})
}

/// The macro creates a tree with a single compile_error macro and with
/// The macro creates a tree with a single compile_error macro and with
/// the corrected span and error message.
macro_rules! pm_compile_error {
($span: expr, $e: expr) => {{
return __make_pm_compile_error($span, $e);
}};
}

/// Checks for null bytes in the data being processed and aborts with an error
/// Checks for null bytes in the data being processed and aborts with an error
/// message if one is detected.
macro_rules! thiserr_nullbyte {
[
Expand All @@ -86,13 +86,13 @@ macro_rules! thiserr_nullbyte {
}};
}

/// A marker that determines the presence of a zero byte (error) in the
/// A marker that determines the presence of a zero byte (error) in the
/// formation of CSTR.
struct ErrDetectedNullByte;

/// The SafeCStrBuilder struct provides an interface for safely creating C-compatible
/// strings (strings that are terminated by a null byte).
/// It guarantees that all data is valid (does not contain any null bytes),
/// The SafeCStrBuilder struct provides an interface for safely creating C-compatible
/// strings (strings that are terminated by a null byte).
/// It guarantees that all data is valid (does not contain any null bytes),
/// except for the trailing null byte.
struct SafeCStrBuilder(Vec<u8>);

Expand Down Expand Up @@ -132,8 +132,8 @@ impl SafeCStrBuilder {
self.0.is_empty()
}

/// Returns a fragment of CSTR bytes.
///
/// Returns a fragment of CSTR bytes.
///
/// (always without trailing null byte)
#[inline]
#[allow(dead_code)]
Expand All @@ -151,15 +151,15 @@ impl SafeCStrBuilder {
Some(..) => Err(ErrDetectedNullByte),
None => {
self.0.extend_from_slice(arr);

Ok(())
}
}
}

/// Converts the CSTR into a COW slice of bytes.
///
/// !Note that if the string is empty, no allocation occurs and a single
/// !Note that if the string is empty, no allocation occurs and a single
/// generic empty CSTR is returned.
pub fn into(mut self) -> Cow<'static, [u8]> {
match self.is_empty() {
Expand All @@ -171,7 +171,7 @@ impl SafeCStrBuilder {
},
false => {
self.0.push(0);

self.0.into()
}
}
Expand Down

0 comments on commit 79e4cff

Please sign in to comment.