Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added array containing all blocks #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

virtualritz
Copy link

@virtualritz virtualritz commented Feb 27, 2023

  • An array, ALL containing references to all blocks to iterate over them.
  • Is behind a feature flag in its own module.
  • Also added/updated docs and README.
  • Added crates.io and docs.rs badges to README.

This closes issue #2.

@virtualritz
Copy link
Author

virtualritz commented Feb 28, 2023

FYI: I need this functionally for my Glyphana unicode viewer.

I figured it is generally useful enough to put it in your crate rather than just have the resp. array in my app's code.

@@ -13,3 +13,8 @@ license = "MIT"
include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE"]

[dependencies]

[features]
default = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed.


[![CI](https://github.com/magiclen/unicode-blocks/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/unicode-blocks/actions/workflows/ci.yml)
[![Documentation](https://docs.rs/unicode-blocks/badge.svg)](https://docs.rs/unicode-blocks)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not used to using this badge.

Copy link
Author

@virtualritz virtualritz Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not used to using this badge.

Most users are though.

If you look at the average popular crate updated in the last two years on crates.io, you'll probably see badges for build/CI status, crates.io version and docs.rs link at the top of the README.

The latter two are for people coming to/accrorss the crate via the repo and not via crates.io. I.e. they will have to dig to find out if this is a published crate at all and if there are docs (the former does not imply the latter, some crates have shoddy docs or the docs.rs build fails).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I will think about it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if shields.io is trustworthy. Displaying their badges might be promoting their services.

Copy link
Author

@virtualritz virtualritz Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.
It's seems what most Rust crate repos on GH are using.
I used something else two years back (forgot the name) but that stopped working some time ago so I switched to shields.io just copying what I saw in others's READMEs.


[![CI](https://github.com/magiclen/unicode-blocks/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/unicode-blocks/actions/workflows/ci.yml)
[![Documentation](https://docs.rs/unicode-blocks/badge.svg)](https://docs.rs/unicode-blocks)
[![Crate](https://img.shields.io/crates/v/unicode-blocks.svg)](https://crates.io/crates/unicode-blocks)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not used to using this badge.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

assert!(unicode_blocks::is_cjk_block(unicode_blocks::CJK_UNIFIED_IDEOGRAPHS));
assert!(
unicode_blocks::is_cjk_block(unicode_blocks::CJK_UNIFIED_IDEOGRAPHS)
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to use line breaks?

## Documentation

https://docs.rs/unicode-blocks

Copy link
Owner

@magiclen magiclen Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my crates on crates.io have them in README.md and therefore I don't want to remove them.

&YI_SYLLABLES,
&ZANABAZAR_SQUARE,
&ZNAMENNY_MUSICAL_NOTATION,
];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not order by the block range?

By the way, I generate UnicodeBlock by using another Rust program which I haven't open-sourced. If we need an array of UnicodeBlocks, this array should also be generated by it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not order by the block range?

I guess the order depends on the application. For my case it didn't really matter. So sure, the refs could as well be ordered by block range.

By the way, I generate UnicodeBlock by using another Rust program which I haven't open-sourced. If we need an array of UnicodeBlocks, this array should also be generated by it.

I agree. It would be nice to include your generator in this crate so people submitting PRs like mine could extend the generator.

This crate contains a list of all unicode blocks and provides some functions to search across them.
This crate contains a list of all unicode blocks and provides some functions
to search across them.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't wrap comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry about that. That was habitual. :)

```
assert!(
unicode_blocks::is_cjk_block(unicode_blocks::CJK_UNIFIED_IDEOGRAPHS)
);
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't see the benefits of using line breaks here.


## Examples

#### Given a character, determine what unicode block contains it.

```rust
assert_eq!(unicode_blocks::BASIC_LATIN, unicode_blocks::find_unicode_block('A').unwrap());
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using ```rust.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why the reduncancy? Your crate is the first one where I ever see this. After all, this is a comment in a Rust source. :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I copy doc comments in lib.rs and paste them to README.md. I don't want to omit the language name for syntax highlighting.

Copy link
Author

@virtualritz virtualritz Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. There is also some cargo extensions that autogenerate (selected parts of) the README from lib.rs.
They all automatically add the rust prefix to resp. code blocks and avoid making mistakes/forgetting stuff when those two files have to be synced.

@Colerar
Copy link

Colerar commented Oct 4, 2023

Maybe &[&UnicodeBlock] is better than [&UnicodeBlock; 327]? The length of this array will change with the Unicode version, potentially breaking API compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants