Skip to content

Commit

Permalink
Upgrade to Rust 1.83 + nightly; nightly is default; prep for edition …
Browse files Browse the repository at this point in the history
…2024; format code
  • Loading branch information
john-cd committed Dec 5, 2024
1 parent 523796b commit 348173a
Show file tree
Hide file tree
Showing 24 changed files with 179 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RUST_VERSION=1.81.0
RUST_VERSION=1.83.0

RUST_IMAGE_LABEL=${RUST_VERSION}-bookworm

Expand Down
36 changes: 22 additions & 14 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ RUN apt-get update \
## --mount=type=cache,target=/var/cache/apt,sharing=locked \
## --mount=type=cache,target=/var/lib/apt,sharing=locked \

## Update Rust if needed (note: `rustup update stable && rustup default stable` is required for Rust 1.74 -> Rust 1.75 somehow)
## Update Rust if needed
RUN rustup update

## Install clippy if needed
RUN rustup component add clippy
# RUN rustup component add clippy

## Install nightly fmt
## NOTE: nightly will be the default until 1.85 (Rust edition 2024) is released
RUN rustup toolchain install nightly \
&& rustup component add rustfmt --toolchain nightly
&& rustup component add rustfmt clippy --toolchain nightly \
&& rustup default nightly

ARG MDBOOK_VERSION

Expand All @@ -41,27 +43,33 @@ RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ca
&& cargo binstall --no-confirm --version ${MDBOOK_VERSION} mdbook
# && cargo binstall --no-confirm --secure cargo-nextest

## TODO Install cargo check tools
# RUN cargo install --locked cargo-deny || true
# RUN cargo install --locked cargo-outdated || true
# RUN cargo install --locked cargo-udeps || true
# RUN cargo install --locked cargo-audit || true
# RUN cargo install --locked cargo-pants || true

WORKDIR /code

## --------------------------------
## Stage for development
FROM base as development

## Additional packages for developement only
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get install -y firefox-esr
# locales xdg-utils desktop-file-utils \
# nano \
## Optional packages for development only
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get install -y firefox-esr
# locales \
# xdg-utils \
# desktop-file-utils \
# nano

## Optional cargo installs for development only
# RUN cargo binstall --no-confirm ripgrep
# RUN cargo install --locked cargo-deny || true
# RUN cargo install --locked cargo-outdated || true
# RUN cargo install --locked cargo-udeps || true
# RUN cargo install --locked cargo-audit || true
# RUN cargo install --locked cargo-pants || true
RUN cargo install cargo-bump

## rustup completions
RUN mkdir -p ~/.local/share/bash-completion/completions/ \
&& rustup completions bash > ~/.local/share/bash-completion/completions/rustup

## https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/command_history/.bash_history" \
&& echo "$SNIPPET" >> "/root/.bashrc"
Expand Down
2 changes: 0 additions & 2 deletions .devcontainer/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ services:
args:
RUST_IMAGE_LABEL: ${RUST_IMAGE_LABEL}
MDBOOK_VERSION: ${MDBOOK_VERSION}
cache_from:
- rust:${RUST_IMAGE_LABEL}
Empty file modified Cargo.lock
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "mdbook-utils"
version = "0.1.4"
authors = ["John CD"]
edition = "2021"
rust-version = "1.75"
rust-version = "1.83"
description = "Tools to manage links, reference definitions, and code examples in Markdown files, especially `mdbook` source directories."
readme = "README.md"
homepage = "https://john-cd.com/mdbook-utils/"
Expand Down
4 changes: 2 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unstable_features = true # Default: false

edition = "2021" # Default: "2015"
style_edition = "2021"
edition = "2024" # Default: "2015"
style_edition = "2024"

newline_style = "Unix" # Default: "Auto"
#max_width = 80 # Default: 100
Expand Down
2 changes: 1 addition & 1 deletion src/build_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use std::path::Path;
use std::process::Command;

use anyhow::anyhow;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;

/// Invokes `mdbook build`.
///
Expand Down
44 changes: 24 additions & 20 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use anyhow::Result;
use serde::Deserialize;
use tracing::debug;

use super::GlobalOpts;
use super::args::CargoTomlDirArgs;
use super::args::DestDirArgs;
use super::args::DestFileArgs;
use super::args::MarkdownDirArgs;
use super::args::UrlArgs;
use super::GlobalOpts;

/// Stores environment variables into a Configuration struct.
/// Defaults apply if not present.
Expand Down Expand Up @@ -158,20 +158,23 @@ impl Configuration {
if let Some(ref mdp) = self.book_markdown_build_dir_path {
debug!("BOOK_MARKDOWN_BUILD_DIR_PATH set: {}", mdp.display());
mdp.clone()
} else if let Ok((_, _, Some(p))) =
super::book_toml::try_parse_book_toml(self.book_root_dir_path.clone())
{
debug!(
"book_markdown_build_dir_path set from `book.toml`: {}",
p.display()
);
p
} else {
debug!(
"book_markdown_build_dir_path set to default: {:?}",
default_dir_path.as_ref()
);
PathBuf::from(default_dir_path.as_ref())
match super::book_toml::try_parse_book_toml(self.book_root_dir_path.clone()) {
Ok((_, _, Some(p))) => {
debug!(
"book_markdown_build_dir_path set from `book.toml`: {}",
p.display()
);
p
}
_ => {
debug!(
"book_markdown_build_dir_path set to default: {:?}",
default_dir_path.as_ref()
);
PathBuf::from(default_dir_path.as_ref())
}
}
},
);

Expand Down Expand Up @@ -244,13 +247,14 @@ impl Configuration {
} else {
let dir: PathBuf = if let Some(ref d) = self.book_html_build_dir_path {
d.clone()
} else if let Ok((_, html_output_dir, _)) =
super::book_toml::try_parse_book_toml(self.book_root_dir_path.clone())
{
// `book.toml`` exists, is parseable and build.build-dir is defined
html_output_dir
} else {
"./book".into()
match super::book_toml::try_parse_book_toml(self.book_root_dir_path.clone()) {
Ok((_, html_output_dir, _)) => {
// `book.toml`` exists, is parseable and build.build-dir is defined
html_output_dir
}
_ => "./book".into(),
}
};
dir.join("sitemap.xml")
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/markdown_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use anyhow::Context;
use anyhow::Result;
use clap::Subcommand;
use console::style;
use dialoguer::theme::ColorfulTheme;
use dialoguer::Confirm;
use dialoguer::theme::ColorfulTheme;

use super::args::*;
use super::config::Configuration;
Expand Down
2 changes: 1 addition & 1 deletion src/dependencies/get_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::io::Write;
use std::path::Path;
use std::process::Command;

use anyhow::anyhow;
use anyhow::Result;
use anyhow::anyhow;
use serde::Deserialize;

/// Stores a dependency to a crate
Expand Down
2 changes: 1 addition & 1 deletion src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use std::path::Path;
use std::path::PathBuf;

use anyhow::bail;
use anyhow::Context;
use anyhow::Error;
use anyhow::bail;
use tracing::info;

/// Check if a path is a directory
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
mod build_book;
mod dependencies;
mod fs;
mod gen;
mod generate;
mod link;
pub mod markdown;
mod parser;
Expand All @@ -38,9 +38,9 @@ use std::io::BufWriter;
use std::io::Write;
use std::path::Path;

use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
use pulldown_cmark::LinkType;
use pulldown_cmark::Parser;

Expand Down Expand Up @@ -280,7 +280,7 @@ where
// for (_, d) in &deps {
// tracing::info!("{:?}", d);
// }
let mut new_links = gen::generate_refdefs_from(deps);
let mut new_links = generate::generate_refdefs_from(deps);

// TODO can we read just the *-refs.md files?
helper(markdown_dir_path, refdef_dest_file_path, |parser, f| {
Expand All @@ -291,7 +291,7 @@ where
println!("NOT IMPLEMENTED!");
let existing_links = Vec::new();

let links = gen::merge_links(existing_links, &mut new_links);
let links = generate::merge_links(existing_links, &mut new_links);
link::write_refdefs_to(links, f)?;
Ok(())
})?;
Expand Down
8 changes: 4 additions & 4 deletions src/link/link_and_linkbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<'a> Link<'a> {
}
}

impl<'a> PartialOrd for Link<'a> {
impl PartialOrd for Link<'_> {
/// PartialOrd implementation for Link
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
// The type is `Ord``,
Expand All @@ -274,7 +274,7 @@ impl<'a> PartialOrd for Link<'a> {
}

// TODO
impl<'a> Ord for Link<'a> {
impl Ord for Link<'_> {
/// Ord implementation for Link
fn cmp(&self, other: &Self) -> Ordering {
self.label
Expand All @@ -285,15 +285,15 @@ impl<'a> Ord for Link<'a> {
}

// TODO
impl<'a> PartialEq for Link<'a> {
impl PartialEq for Link<'_> {
/// PartialEq implementation for Link
fn eq(&self, other: &Self) -> bool {
(self.label == other.label) && (self.url == other.url) && (self.title == other.title)
}
}

/// Eq implementation for Link
impl<'a> Eq for Link<'a> {}
impl Eq for Link<'_> {}

#[cfg(test)]
mod test {
Expand Down
Loading

0 comments on commit 348173a

Please sign in to comment.