dtolnay / Indoc
Licence: other
Indented document literals for Rust
Stars: ✭ 209
Programming Languages
rust
11053 projects
Labels
Projects that are alternatives of or similar to Indoc
Hexo Prism Plugin
Hexo plugin for code highlighting by prism.js, supporting JSX syntax
Stars: ✭ 195 (-6.7%)
Mutual labels: plugin
Network Media Library
Network Media Library plugin for WordPress Multisite
Stars: ✭ 203 (-2.87%)
Mutual labels: plugin
Composer Patches
Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and composer command for testing/troubleshooting patches.
Stars: ✭ 196 (-6.22%)
Mutual labels: plugin
Obs Ios Camera Source
Use your iPhone camera as a video source in OBS Studio and stream high quality video from your iPhone's camera over USB
Stars: ✭ 199 (-4.78%)
Mutual labels: plugin
Casbin Authz Plugin
Docker Authorization Plugin based on Casbin
Stars: ✭ 204 (-2.39%)
Mutual labels: plugin
Drone Cache
A Drone plugin for caching current workspace files between builds to reduce your build times
Stars: ✭ 194 (-7.18%)
Mutual labels: plugin
Artist
An artist creates views. Artist is a Gradle plugin that codegens a base set of Android Views.
Stars: ✭ 208 (-0.48%)
Mutual labels: plugin
Dont Break
Checks if the current version of your package would break dependent projects
Stars: ✭ 200 (-4.31%)
Mutual labels: plugin
Wechatplugin Macos
No description or website provided.
Stars: ✭ 13,280 (+6254.07%)
Mutual labels: plugin
Admob Plus
Trustable AdMob Plugin for Cordova, Capacitor, Ionic
Stars: ✭ 195 (-6.7%)
Mutual labels: plugin
Argusapm
Powerful, comprehensive (Android) application performance management platform. 360线上移动性能检测平台
Stars: ✭ 2,452 (+1073.21%)
Mutual labels: plugin
Flutter statusbarcolor
A package can help you to change your flutter app's statusbar's color or navigationbar's color programmatically.
Stars: ✭ 203 (-2.87%)
Mutual labels: plugin
Qtfirebase
An effort to bring Google's Firebase C++ API to Qt + QML
Stars: ✭ 208 (-0.48%)
Mutual labels: plugin
Mapbox Gl Geocoder
Geocoder control for mapbox-gl-js using Mapbox Geocoding API
Stars: ✭ 207 (-0.96%)
Mutual labels: plugin
Plugins
Plugins for Flutter maintained by the Flutter team
Stars: ✭ 14,956 (+7055.98%)
Mutual labels: plugin
Indented Documents (indoc)
This crate provides a procedural macro for indented string literals. The
indoc!()
macro takes a multiline string literal and un-indents it at compile
time so the leftmost non-space character is in the first column.
[dependencies]
indoc = "1.0"
Compiler requirement: rustc 1.45 or greater.
Using indoc
use indoc::indoc;
fn main() {
let testing = indoc! {"
def hello():
print('Hello, world!')
hello()
"};
let expected = "def hello():\n print('Hello, world!')\n\nhello()\n";
assert_eq!(testing, expected);
}
Indoc also works with raw string literals:
use indoc::indoc;
fn main() {
let testing = indoc! {r#"
def hello():
print("Hello, world!")
hello()
"#};
let expected = "def hello():\n print(\"Hello, world!\")\n\nhello()\n";
assert_eq!(testing, expected);
}
And byte string literals:
use indoc::indoc;
fn main() {
let testing = indoc! {b"
def hello():
print('Hello, world!')
hello()
"};
let expected = b"def hello():\n print('Hello, world!')\n\nhello()\n";
assert_eq!(testing[..], expected[..]);
}
Formatting macros
The indoc crate exports four additional macros to substitute conveniently for the standard library's formatting macros:
-
formatdoc!($fmt, ...)
— equivalent toformat!(indoc!($fmt), ...)
-
printdoc!($fmt, ...)
— equivalent toprint!(indoc!($fmt), ...)
-
eprintdoc!($fmt, ...)
— equivalent toeprint!(indoc!($fmt), ...)
-
writedoc!($dest, $fmt, ...)
— equivalent towrite!($dest, indoc!($fmt), ...)
use indoc::printdoc;
fn main() {
printdoc! {"
GET {url}
Accept: {mime}
",
url = "http://localhost:8080",
mime = "application/json",
}
}
Explanation
The following rules characterize the behavior of the indoc!()
macro:
- Count the leading spaces of each line, ignoring the first line and any lines that are empty or contain spaces only.
- Take the minimum.
- If the first line is empty i.e. the string begins with a newline, remove the first line.
- Remove the computed number of spaces from the beginning of each line.
Unindent
Indoc's indentation logic is available in the unindent
crate. This may be
useful for processing strings that are not statically known at compile time.
The crate exposes two functions:
unindent(&str) -> String
unindent_bytes(&[u8]) -> Vec<u8>
use unindent::unindent;
fn main() {
let indented = "
line one
line two";
assert_eq!("line one\nline two", unindent(indented));
}
Licensed under either of LicenseApache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].