Skip to content

Commit

Permalink
Merge pull request #57 from nyurik/lints
Browse files Browse the repository at this point in the history
Minor lints and cleanups
  • Loading branch information
kilork authored Feb 14, 2025
2 parents 683116e + fef6562 commit 0cf54fc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

## <a name='Legal'></a>Legal

Dual-licensed under `MIT` or the [UNLICENSE](http://unlicense.org/).
Dual-licensed under `MIT` or the [Unlicense](http://unlicense.org/).

## <a name='Features'></a>Features

Expand Down Expand Up @@ -159,7 +159,7 @@ Reference resources in your `HTML` (`static/index.html`):
```html
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
## <a name='Legal'></a>Legal
Dual-licensed under `MIT` or the [UNLICENSE](http://unlicense.org/).
Dual-licensed under `MIT` or the [Unlicense](http://unlicense.org/).
## <a name='Features'></a>Features
- Embed static resources in single self-contained executuble
- Embed static resources in single self-contained executable
- Serve static resources in `actix-web`
- Install dependencies with [npm](https://npmjs.org) package manager
- Run custom `npm` run commands (such as [webpack](https://webpack.js.org/))
Expand Down
17 changes: 11 additions & 6 deletions src/resource_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ use std::{collections::HashMap, ops::Deref, rc::Rc};
/// use actix_web::App;
///
/// fn main() {
/// // serve root directory with default options:
/// // - resolve index.html
/// // serve root directory with default options:
/// // - resolve index.html
/// let files: HashMap<&'static str, static_files::Resource> = HashMap::new();
/// let app = App::new()
/// .service(actix_web_static_files::ResourceFiles::new("/", files));
/// // or subpath with additional option to not resolve index.html
/// // or subpath with additional option to not resolve index.html
/// let files: HashMap<&'static str, static_files::Resource> = HashMap::new();
/// let app = App::new()
/// .service(actix_web_static_files::ResourceFiles::new("/imgs", files)
Expand All @@ -54,6 +54,7 @@ pub struct ResourceFilesInner {
const INDEX_HTML: &str = "index.html";

impl ResourceFiles {
#[must_use]
pub fn new(path: &str, files: HashMap<&'static str, Resource>) -> Self {
let inner = ResourceFilesInner {
path: path.into(),
Expand All @@ -69,6 +70,7 @@ impl ResourceFiles {

/// By default trying to resolve '.../' to '.../index.html' if it exists.
/// Turn off this resolution by calling this function.
#[must_use]
pub fn do_not_resolve_defaults(mut self) -> Self {
self.not_resolve_defaults = true;
self
Expand All @@ -77,6 +79,7 @@ impl ResourceFiles {
/// Resolves not found references to this path.
///
/// This can be useful for angular-like applications.
#[must_use]
pub fn resolve_not_found_to<S: ToString>(mut self, path: S) -> Self {
self.not_found_resolves_to = Some(path.to_string());
self
Expand All @@ -85,15 +88,17 @@ impl ResourceFiles {
/// Resolves not found references to root path.
///
/// This can be useful for angular-like applications.
#[must_use]
pub fn resolve_not_found_to_root(self) -> Self {
self.resolve_not_found_to(INDEX_HTML)
}

/// If this is called, we will use an [actix_web::guard::Guard] to check if this request should be handled.
/// If this is called, we will use a [`Guard`] to check if this request should be handled.
/// If set to true, we skip using the handler for files that haven't been found, instead of sending 404s.
/// Would be ignored, if `resolve_not_found_to` or `resolve_not_found_to_root` is used.
///
/// Can be useful if you want to share files on a (sub)path that's also used by a different route handler.
#[must_use]
pub fn skip_handler_when_not_found(mut self) -> Self {
self.use_guard = true;
self
Expand Down Expand Up @@ -178,9 +183,9 @@ impl HttpServiceFactory for ResourceFiles {
}

impl ServiceFactory<ServiceRequest> for ResourceFiles {
type Config = ();
type Response = ServiceResponse;
type Error = Error;
type Config = ();
type Service = ResourceFilesService;
type InitError = ();
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
Expand Down Expand Up @@ -383,7 +388,7 @@ fn get_pathbuf(path: &str) -> Result<String, UriSegmentError> {
} else if cfg!(windows) && segment.contains('\\') {
return Err(UriSegmentError::BadChar('\\'));
} else {
buf.push(segment)
buf.push(segment);
}
}

Expand Down
4 changes: 2 additions & 2 deletions templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

## <a name='Legal'></a>Legal

Dual-licensed under `MIT` or the [UNLICENSE](http://unlicense.org/).
Dual-licensed under `MIT` or the [Unlicense](http://unlicense.org/).

## <a name='Features'></a>Features

- Embed static resources in single self-contained executuble
- Embed static resources in single self-contained executable
- Serve static resources in `actix-web`
- Install dependencies with [npm](https://npmjs.org) package manager
- Run custom `npm` run commands (such as [webpack](https://webpack.js.org/))
Expand Down

0 comments on commit 0cf54fc

Please sign in to comment.